In this exercise, you’re going to add a whole new Chromium feature, bringing together everything you already learned.
A community of pixies has been discovered living in a remote rainforest. It’s important that we get Chromium for Pixies delivered to them as soon as possible.
The requirement is to translate all Chromium’s UI strings into Pixie language.
There’s not time to wait for proper translations, but fortunately pixie language is very close to English, and it turns out there’s a Rust crate which does the translation.
In fact, you already imported that crate in the previous exercise.
(Obviously, real translations of Chrome require incredible care and diligence. Don’t ship this!)
ResourceBundle::MaybeMangleLocalizedString so that it uwuifies all
strings before display. In this special build of Chromium, it should always do
this irrespective of the setting of
If you’ve done everything right across all these exercises, congratulations, you should have created Chrome for pixies!
- UTF16 vs UTF8. Students should be aware that Rust strings are always UTF8, and
will probably decide that it’s better to do the conversion on the C++ side
base::UTF16ToUTF8and back again.
- If students decide to do the conversion on the Rust side, they’ll need to
String::from_utf16, consider error handling, and consider which CXX supported types can transfer a lot of u16s.
- Students may design the C++/Rust boundary in several different ways, e.g.
taking and returning strings by value, or taking a mutable reference to a
string. If a mutable reference is used, CXX will likely tell the student that
they need to use
Pin. You may need to explain what
Pindoes, and then explain why CXX needs it for mutable references to C++ data: the answer is that C++ data can’t be moved around like Rust data, because it may contain self-referential pointers.
- The C++ target containing
ResourceBundle::MaybeMangleLocalizedStringwill need to depend on a
rust_static_librarytarget. The student probably already did this.
rust_static_librarytarget will need to depend on