Add free to String, update hello_world_harder

This commit is contained in:
Sofia 2025-07-28 00:44:52 +03:00
parent 1f56fa5dc3
commit 8838223a7d
2 changed files with 6 additions and 9 deletions

View File

@ -1,23 +1,16 @@
import std::print;
import std::from_str;
import std::set_char;
import std::free_string;
import std::String;
fn main() {
let mut test = String::from("hello");
test.push(String::from(" world"));
test.add_char('!');
test.add_char('\n');
test.push(String::from(" world: "));
test.push_num(175);
print(test);
free_string(&test);
test.free();
return;
}

View File

@ -75,6 +75,10 @@ impl String {
else if rem == 8 { self.add_char('8'); }
else if rem == 9 { self.add_char('9'); }
}
pub fn free(&self) {
free((*self).inner as *u8);
}
}
impl binop (lhs: String) + (rhs: *char) -> String {