AK is Ladybird’s foundational standard library providing containers, smart pointers, strings, and utilities used throughout the browser codebase.
AK (short for “Agner’s Kit”) is Ladybird’s custom standard library that provides fundamental data structures, smart pointers, string types, and utility classes. Every component in Ladybird depends on AK for basic functionality.
// Create using make<T>()NonnullOwnPtr<MyClass> obj = make<MyClass>(arg1, arg2);// For fallible allocationauto obj_or_error = try_make<MyClass>();if (obj_or_error.is_error()) { // Handle allocation failure}
NonnullOwnPtr cannot be null, making it perfect for return types and parameters where null is invalid. It’s equivalent to passing by reference (&) but with ownership transfer.
class MyObject : public RefCounted<MyObject> { // ...};NonnullRefPtr<MyObject> obj1 = make_ref_counted<MyObject>();RefPtr<MyObject> obj2 = obj1; // Reference count is now 2
void process(StringView text) { // No copying, just a pointer and length dbgln("Processing: {}", text);}String owned = "data"_string;process(owned.bytes_as_string_view());process("literal"sv);
StringBuilder builder;builder.append("Hello "sv);builder.append("World"sv);builder.appendff(", the answer is {}!", 42);auto result = builder.to_string();
ErrorOr<String> read_file(StringView path) { // Return either String or Error return String::from_utf8(data);}// Using TRY macro for error propagationErrorOr<void> process() { auto content = TRY(read_file("/path/to/file"sv)); // Use content... return {};}
AK is designed to have zero dependencies - it doesn’t even depend on the C++ standard library for most operations. This makes it highly portable and predictable.