-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add env chapter to book #788
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough about the env to say this is good but it's definitely better to have some docs about it! +1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
1. **`Key`s should be `const`s with unique names.** If you need to use a custom | ||
key, you should declare it as a `const`, and give it a unique name. By | ||
convention, you should namespace your keys using something like [reverse-DNS] | ||
notation, or even just prefixing them with the name of your app. | ||
|
||
```rust,noplaypen | ||
const BAD_NAME: Key<f64> = Key::new("height"); | ||
const GOOD_NAME: Key<f64> = Key::new("com.example.my-app.main-view-height"); | ||
``` | ||
1. **`Key`s must always be set before they are used.** In practice this means | ||
that most keys are set when your application launches, using | ||
[`AppLauncher::configure_env`]. Once a key has been added to the `Env`, it | ||
cannot be deleted, although it can be overwritten. | ||
|
||
1. **Values can only be overwritten by values of the same type.** If you have a | ||
`Key<f64>`, assuming that key has already been added to the `Env`, you cannot | ||
replace it with any other type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to add (at least the bold parts) of this list directly to the Env
docs as well
[`Env`]: https://docs.rs/druid/0.4.0/druid/struct.Env.html | ||
[`Key`]: https://docs.rs/druid/0.4.0/druid/struct.Key.html | ||
[`Value`]: https://docs.rs/druid/0.4.0/druid/struct.Value.html | ||
[`LocalizedString`]: https://docs.rs/druid/0.4.0/druid/struct.LocalizedString.html | ||
[`resolve`]: https://docs.rs/druid/0.4.0/druid/struct.LocalizedString.html#method.resolve | ||
[localization]: ./localization.md | ||
[reverse-DNS]: https://en.wikipedia.org/wiki/Reverse_domain_name_notation | ||
[`AppLauncher::configure_env`]: https://docs.rs/druid/0.4.0/druid/struct.AppLauncher.html#method.configure_env | ||
[`KeyOrValue`]: https://docs.rs/druid/0.4.0/druid/enum.KeyOrValue.html | ||
[`EnvScope`]: https://docs.rs/druid/0.4.0/druid/widget/struct.EnvScope.html | ||
[`WidgetExt`]: https://docs.rs/druid/0.4.0/druid/trait.WidgetExt.html | ||
[`env_scope`]: https://docs.rs/druid/0.4.0/druid/trait.WidgetExt.html#method.env_scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite a few of those are dead ends (KeyOrValue
for example), I suppose they did not yet exist in druid 0.4.0
and you added them as a reminder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will probably work with 0.5.0
. I confirmed KeyOrValue
working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I want to keep this at 0.4.0 and then I'll bump to 0.5.0 all at once.
No description provided.