Skip to content

Lamination: Don't allow errors to occur in constructors of any class. #42

@graphitemaster

Description

@graphitemaster

Move to a Result<T> system of static methods on types like String and Vector which can fail when allocating memory such that the constructor cannot fail. That means copies like the following:

String foo = "something that can fail";

Will no longer compile and instead you'll have to write:

Result<String> foo = "something that can fail";

Which will be enabled by Result<T> calling a special init_from_result static method.

Similarly, constructors like

Vector<Byte> data{1024};

Will no longer work, instead you'll write something like:

auto data = Vector<Byte>::create_with_size(1024);

Which gives a Result<Vector<Byte>> data

And likewise, copy constructors will call special copy_from_result static methods, so

Result<String> a = "hello world";
String b = move(*a);
String c = b; // error
Result<String> d = b; // works

The Result<T> type is special in that it will allow anything returning Result<T> to return an Error type which is just a wrapped String indicating the resulting error.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions