- Error Handling
- Standard Containers
- Time Utils
- Standard Trivial Type Wrapper
- File Formats
- TCP/UDP Utils
- Cryptography
If condition is false, the program will panic with the error message.
assert(condition, "error message");Panic with the error message.
panic("error message");Panic with the error message "unreachable".
unreachable();Panic with the error message "unimplemented".
unimplemented();Source: list<T>
Linked list that accepts both trivial and non-trivial types.
- If
Tis non-trivial type, it accepts types with these methods:func clone(self) -> Tfunc delete(self)
- If
Tis trivial type, it could be used directly.
Example:
func main() -> i32 {
var a = list<str>::instance();
var b = list<i64>::instance();
var s = str::from("hello world!");
a.push_back(s.__ptr__()); // s will do copy here
b.push_back(123); // do not need pointer type
a.delete();
b.delete();
s.delete();
return 0;
}Source: queue<T>
Queue that accepts both trivial and non-trivial types.
- If
Tis non-trivial type, it accepts types with these methods:func clone(self) -> Tfunc delete(self)
- If
Tis trivial type, it could be used directly.
Example:
func main() -> i32 {
var a = queue<str>::instance();
var b = queue<i32>::instance();
var s = str::from("hello world!");
a.push(s.__ptr__());
a.pop();
b.push(123);
b.pop();
a.delete();
b.delete();
s.delete();
return 0;
}Source: vec<T>
Vector that accepts both trivial and non-trivial types.
- If
Tis non-trivial type, it accepts types with these methods:func clone(self) -> Tfunc delete(self)
- If
Tis trivial type, it could be used directly.
Example:
func main() -> i32 {
var a = vec<str>::instance();
var s = str::from("hello world!");
a.push(s.__ptr__());
a.pop_back();
var b = vec<i32>::instance();
b.push(123);
a.delete();
s.delete();
b.delete();
return 0;
}Source: hashset<T>
Hashset, T accepts types with these methods:
func clone(self) -> Tfunc delete(self)func hash(self) -> u64
Example:
func main() -> i32 {
var a = hashset<str>::instance();
var s = str::from("hello world!");
a.insert(s.__ptr__());
a.delete();
s.delete();
return 0;
}Source: pair<K, V>
Pair, K and V accept both trivial and non-tribial types.
Example:
func main() -> i32 {
var a = pair<str, i32>::instance(s.__ptr__(), 123);
var b = pair<i32, str>::instance(123, s.__ptr__());
var c = pair<i32, i32>::instance(123, 456);
var d = pair<str, str>::instance(s.__ptr__(), s.__ptr__());
s.delete();
a.delete();
b.delete();
c.delete();
d.delete();
return 0;
}Source: hashmap<K, V>
Hashmap, K and V accepts types with these methods:
func clone(self) -> Kfunc delete(self)
And K must implement func hash(self) -> u64.
Example:
func main() -> i32 {
var a = hashmap<str, basic<i32>>::instance();
var s = str::from("hello world!");
a.insert(s.__ptr__(), basic<i32>::wrap(1).__ptr__());
a.delete();
s.delete();
return 0;
}Source: chrono
chrono::timestamp() -> time_t:
return the current timestamp in 64 bit time_t.
chrono::localtime() -> str:
return string of local time, for example "2025-08-15 00:00:00".
chrono::high_resolution_time() -> timespec:
return current timespec (64 bit sec, 64 bit nsec).
chrono::duration_s(start: timespec, end: timespec) -> f64chrono::duration_ms(start: timespec, end: timespec) -> f64chrono::duration_us(start: timespec, end: timespec) -> f64chrono::duration_ns(start: timespec, end: timespec) -> f64
return duration in seconds, milliseconds, microseconds and nanoseconds.
Source: basic<T>
Basic type, T accepts primitive types.
This wrapper could make basic types able to be used in hashset and hashmap.
Because hashset and hashmap now need the key type with the method
func hash(self) -> u64.
Example:
func main() -> i32 {
var a = hashset<basic<i32>>::instance();
a.insert(basic<i32>::wrap(1));
a.delete();
return 0;
}Source: json
Not stable, methods may change.
use std::json::{ json };
use std::str::{ str };
use std::libc::{ free };
use std::io::{ io };
func main() -> i32 {
var input = str::from("{ \"a\": 1, \"b\": 2 }");
defer input.delete();
var j = json::parse(input.__ptr__());
defer {
j->delete();
free(j => i8*);
}
if (!j->is_invalid()) {
var s = j->to_string();
defer s.delete();
io::stdout().out(s.c_str).endln();
}
return 0;
}See example for std::tcp in example/socket/tcp_example.colgm
See example for std::udp in example/socket/udp_example.colgm
See example for std::crypto::md5 in test/md5_test.colgm
See example for std::crypto::base64 in test/base64_test.colgm
