-
Notifications
You must be signed in to change notification settings - Fork 13
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 Ufo::new_layer(name) method #84
Comments
When we create a new UFO we always add I guess I Would want to think about this from an actual user's perspective: what are they trying to achieve? I don't use layers in norad right now, so I'm not sure. The problem with I think that a simple and reasonable approach might be to just expect the caller to check if a given layer exists, and create it if not; this will not be heavily used API, so I don't think we should get too fancy. I think that returning an error if the layer already exists is a simple and correct solution. 🤷 |
We only create the default layer. I just hit this again where I iterate over a data source and sometimes write a background layer for a glyph. The code now looks like this: if let Some(parent_name) = layer.name.strip_prefix("mask.") {
if let Some(drawn_instance) = drawn_instances.get_mut(parent_name) {
match drawn_instance.find_layer_mut(|l| l.name == "public.background") {
// If we already have a background layer...
Some(background) => // ...,
// Otherwise make a new one and insert the glyph.
None => {
// creation dance...
}
};
}
} else {
// ...
} |
Should insert an empty new named layer and return a mutable reference to it. UX problem: what if your chosen layer name exists already? Return
Result<Error, &mut Layer>
?Maybe even a combination method like
get_or_insert_new(name)
? Or something mirroring https://doc.rust-lang.org/std/option/enum.Option.html#method.get_or_insert. Use case is mutably grabbing e.g. thepublic.background
layer or creating it if it doesn't exist yet. For when you just want to add stuff into it.The text was updated successfully, but these errors were encountered: