Skip to content
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

Merged
merged 1 commit into from
Apr 1, 2020
Merged

Add env chapter to book #788

merged 1 commit into from
Apr 1, 2020

Conversation

cmyr
Copy link
Member

@cmyr cmyr commented Mar 31, 2020

No description provided.

Copy link
Collaborator

@fishrockz fishrockz left a 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

Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Collaborator

@luleyleo luleyleo left a 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 👍

Comment on lines +34 to +50
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.
Copy link
Collaborator

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

Comment on lines +87 to +98
[`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
Copy link
Collaborator

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?

Copy link
Member

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.

Copy link
Member Author

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.

@cmyr cmyr merged commit bebc5fe into master Apr 1, 2020
@cmyr cmyr deleted the book-env-docs branch April 1, 2020 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants