2 releases
0.4.1 | Dec 3, 2020 |
---|---|
0.4.0 | Dec 2, 2020 |
#632 in Testing
22KB
359 lines
Polyhorn
A library for rapidly building cross-platform apps in Rust 🦀.
Polyhorn is a Rust library for building user interfaces. For users familiar with React or React Native, this library will be very similar in purpose.
It also comes with its own command line interface that makes it easy to start a new project and to build and run existing projects.
Colloquially, both are called Polyhorn.
🚧 Warning: Polyhorn is still very much a work-in-progress, which means that there will probably be many breaking changes and missing features before its official launch (sorry for this).
Get Started
Installation
Installation of Polyhorn is easy and takes just a few seconds. If you're new to Rust, you also need to install Rust first with step 1 below. If you're already using Rust, you can skip step 1 and install Polyhorn with step 2.
-
If you don't already have Rust installed, install Rust with rustup.
$ curl -sSf https://sh.rustup.rs | sh
-
Now, install Polyhorn with cargo, the Rust-provided package manager.
$ cargo install polyhorn
Start a Project
Starting a new project from one of our built-in templates is easy. For an almost blank project, run:
$ polyhorn new hello-world
You can replace hello-world
with the name of your app. Make sure it contains
only alphanumerical characters and dashes.
This will generate a directory with the following structure:
hello-world/
├── .gitignore
├── assets
│ └── .gitkeep
└── src
└── lib.rs
This is the content of src/lib.rs
:
use polyhorn::prelude::*;
#[derive(Default)]
pub struct App {}
impl Component for App {
fn render(&self, _manager: &mut Manager) -> Element {
poly!(<Window>
<View style=!{
align-items: center;
justify-content: center;
background-color: red;
height: 100%;
}>
<Text style=!{ color: white; }>
"Welcome to your Polyhorn app!"
</Text>
</View>
</Window>)
}
}
polyhorn::render!(<App />);
Run a Project
In your command line, navigate to your project. For example, if you followed the
instructions above, you should now be in hello-world/
. Then, decide on which
platform you want to run. Note that all platforms share the same codebase, so
you don't need to plan ahead.
Running on iOS
If you want to run your app on an iOS simulator, run this command:
$ polyhorn run ios
It will ask you to select an available simulator.
lib.rs
:
Polyhorn tests are the most ergonomic way to test Polyhorn apps.
Dependencies
~9–24MB
~375K SLoC