Skip to content

Instantly share code, notes, and snippets.

@zbraniecki
Created January 25, 2021 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbraniecki/518423d03b17a0b17e385f74b62f305d to your computer and use it in GitHub Desktop.
Save zbraniecki/518423d03b17a0b17e385f74b62f305d to your computer and use it in GitHub Desktop.
FFI for ICU4X example
class DateTimeFormat {
public:
Result<DateTimeFormat, ()> tryNew(string aLocale, options aOptions);
string format(date aDate);
protected:
DateTimeFormat(string aLocale, ffi::DateTimeFormatData aData);
UniquePtr<ffi::DateTimeFormatData> mData;
};
Result<DateTimeFormat, ()>
DateTimeFormat::tryNew(string aLocale, options aOptions) {
ffi::RequestData request = ffi::DateTimeFormat::Request(aLocale, aOptions);
mData = ffi::DataProvider::GetData(request); // fallible? async?
return new DateTimeFormat(aLocale, mData);
}
string
DateTimeFormat::Format(date aDate) {
return ffi::DateTimeFormat::Format(aDate, mData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment