Struct napchart::Napchart [−][src]
pub struct Napchart { pub shape: ChartShape, // some fields omitted }
Expand description
A napchart, as seen on https://napchart.com/
Fields
shape: ChartShape
The default shape of the napchart on napchart.com
Implementations
Append a new blank lane to the chart and return a mutable reference to it.
let mut chart = Napchart::default(); let mut lane = chart.add_lane(); assert!(lane.is_empty()); assert_eq!(chart.lanes_len(), 1);
Get a reference to the given lane, or None if out of bounds.
let mut chart = Napchart::default(); chart.add_lane(); assert!(chart.get_lane(0).is_some()); assert!(chart.get_lane(1).is_none());
Get a mutable reference to the given lane, or None if out of bounds.
let mut chart = Napchart::default(); chart.add_lane(); assert!(chart.get_lane_mut(0).is_some()); assert!(chart.get_lane_mut(1).is_none());
Remove the given lane from the chart and return it, or None if out of bounds.
let mut chart = Napchart::default(); chart.add_lane(); let lane = chart.remove_lane(0); assert!(lane.is_some()); assert_eq!(chart.lanes_len(), 0);
Get the total number of lanes in the chart.
let mut chart = Napchart::default(); assert_eq!(chart.lanes_len(), 0); chart.add_lane(); assert_eq!(chart.lanes_len(), 1); chart.add_lane(); assert_eq!(chart.lanes_len(), 2); chart.remove_lane(1); chart.remove_lane(0); assert_eq!(chart.lanes_len(), 0);
Create an UploadBuilder with a reference to this chart.
let client = BlockingClient::default(); let chart = Napchart::default(); let upload: napchart::api::UploadBuilder = chart.upload().title("My Cool Chart"); assert!(client.create_snapshot(upload).is_ok());
Getters and setters for color tags and custom colors
Get the text tag for a color.
let mut chart = Napchart::default(); // Napcharts start out with no color tags assert!(chart.get_color_tag(ChartColor::Blue).is_none()); chart.set_color_tag(ChartColor::Blue, "Core Sleep").unwrap(); assert_eq!(chart.get_color_tag(ChartColor::Blue), Some("Core Sleep"));
Get an iterator over ChartColors and their tags.
let mut chart = Napchart::default(); chart.set_color_tag(ChartColor::Blue, "Nap"); chart.set_color_tag(ChartColor::Gray, "Core"); let mut iter = chart.color_tags_iter(); assert!(iter.next().is_some()); assert!(iter.next().is_some()); assert!(iter.next().is_none());
pub fn set_color_tag<T: ToString>(
&mut self,
color: ChartColor,
tag: T
) -> Result<Option<String>, ErrorKind>
pub fn set_color_tag<T: ToString>(
&mut self,
color: ChartColor,
tag: T
) -> Result<Option<String>, ErrorKind>
Set the text tag for a color, returning the value that was replaced. Returns ErrorKind::CustomColorUnset if you attempt to set the tag on an undefined custom color.
let mut chart = Napchart::default(); let original: Option<String> = chart.set_color_tag(ChartColor::Blue, "Core Sleep").unwrap(); assert!(original.is_none()); // Replaced nothing assert_eq!(chart.get_color_tag(ChartColor::Blue), Some("Core Sleep")); let second: Option<String> = chart.set_color_tag(ChartColor::Blue, "Nap").unwrap(); assert_eq!(second, Some(String::from("Core Sleep"))); assert_eq!(chart.get_color_tag(ChartColor::Blue), Some("Nap"));
pub fn set_color_tag_unchecked<T: ToString>(
&mut self,
color: ChartColor,
tag: T
) -> Option<String>
pub fn set_color_tag_unchecked<T: ToString>(
&mut self,
color: ChartColor,
tag: T
) -> Option<String>
Set the text tag for a color. This function does not check custom colors are valid!! It is invalid/undefined behavior to upload a napchart that uses a custom color without defining its colorvalue,, “uses” meaning “has a color tag” and/or “is set on an element”.
use colorsys::Rgb; let mut chart = Napchart::default(); chart.set_custom_color(ChartColor::Custom0, Rgb::from_hex_str("DEDBEF").unwrap()); let res = chart.set_color_tag(ChartColor::Custom0, "Dead Beef"); assert!(res.is_ok()); chart.remove_custom_color(ChartColor::Custom0); let res = chart.set_color_tag(ChartColor::Custom0, "Dead Beef"); assert!(res.is_err()); assert!(matches!(res.unwrap_err(), napchart::ErrorKind::CustomColorUnset(0)));
Removing the text tag for a color, returning the previous value.
let mut chart = Napchart::default(); let original: Option<String> = chart.set_color_tag(ChartColor::Blue, "Core Sleep").unwrap(); assert!(original.is_none()); // Replaced nothing assert_eq!(chart.get_color_tag(ChartColor::Blue), Some("Core Sleep")); let second: Option<String> = chart.set_color_tag(ChartColor::Blue, "Nap").unwrap(); assert_eq!(second, Some(String::from("Core Sleep"))); assert_eq!(chart.get_color_tag(ChartColor::Blue), Some("Nap"));
Gets the rgb value of a custom color. May only be called with CustomX ChartColors (asserts ChartColor::is_custom).
use colorsys::Rgb; let mut chart = Napchart::default(); assert!(chart.get_custom_color(ChartColor::Custom0).is_none()); chart.set_custom_color(ChartColor::Custom0, Rgb::from_hex_str("DEDBEF").unwrap()); assert_eq!(chart.get_custom_color(ChartColor::Custom0), Some(&Rgb::from((0xDE, 0xDB, 0xEF))));
Get an iterator over custom color (as usize indexes) and their RGB values.
use colorsys::Rgb; let mut chart = Napchart::default(); chart.set_custom_color(ChartColor::Custom2, Rgb::from((0xDE, 0xDB, 0xEF))); chart.set_custom_color(ChartColor::Custom0, Rgb::from((0xB0, 0x0B, 0xE5))); let mut iter = chart.custom_colors_iter_index(); assert_eq!(iter.next(), Some((0, &Rgb::from((0xB0, 0x0B, 0xE5))))); assert_eq!(iter.next(), Some((2, &Rgb::from((0xDE, 0xDB, 0xEF))))); assert!(iter.next().is_none());
Get an iterator over custom color (as ChartColors) and their RGB values.
use colorsys::Rgb; let mut chart = Napchart::default(); chart.set_custom_color(ChartColor::Custom2, Rgb::from((0xDE, 0xDB, 0xEF))); chart.set_custom_color(ChartColor::Custom0, Rgb::from((0xB0, 0x0B, 0xE5))); let mut iter = chart.custom_colors_iter_color(); assert_eq!(iter.next(), Some((ChartColor::Custom0, &Rgb::from((0xB0, 0x0B, 0xE5))))); assert_eq!(iter.next(), Some((ChartColor::Custom2, &Rgb::from((0xDE, 0xDB, 0xEF))))); assert!(iter.next().is_none());
Sets the rgb value of a custom color, returning the previous value. May only be called with CustomX ChartColors (asserts ChartColor::is_custom).
use colorsys::Rgb; let mut chart = Napchart::default(); assert!(chart.get_custom_color(ChartColor::Custom0).is_none()); chart.set_custom_color(ChartColor::Custom0, Rgb::from_hex_str("DEDBEF").unwrap()); assert_eq!(chart.get_custom_color(ChartColor::Custom0), Some(&Rgb::from((0xDE, 0xDB, 0xEF))));
Unsets the rgb value of a custom color, returning the previous value. May only be called with CustomX ChartColors (asserts ChartColor::is_custom). Also removes the color_tag associated with the custom color. (See _unchecked)
use colorsys::Rgb; let mut chart = Napchart::default(); chart.set_custom_color(ChartColor::Custom0, Rgb::from_hex_str("DEDBEF").unwrap()); chart.set_color_tag(ChartColor::Custom0, "Dead Beef").unwrap(); chart.remove_custom_color(ChartColor::Custom0); assert!(chart.get_custom_color(ChartColor::Custom0).is_none()); assert!(chart.get_color_tag(ChartColor::Custom0).is_none());
Unsets the rgb value of a custom color, returning the previous value. May only be called with CustomX ChartColors (asserts ChartColor::is_custom). Does not remove a color_tag associated with the custom color. It is invalid/undefined behavior to upload a napchart that uses a custom color without defining its colorvalue,, “uses” meaning “has a color tag” and/or “is set on an element”.
use colorsys::Rgb; let mut chart = Napchart::default(); chart.set_custom_color(ChartColor::Custom0, Rgb::from_hex_str("DEDBEF").unwrap()); chart.set_color_tag(ChartColor::Custom0, "Dead Beef").unwrap(); chart.remove_custom_color_unchecked(ChartColor::Custom0); assert!(chart.get_custom_color(ChartColor::Custom0).is_none()); assert!(chart.get_color_tag(ChartColor::Custom0).is_some()); // UB if uploaded!
Builder functions to create new napcharts.
let chart = Napchart::default() .lanes(3) .shape(ChartShape::Wide); assert_eq!(chart.lanes_len(), 3); assert_eq!(chart.shape, ChartShape::Wide);
Return Napchart with shape set.
let chart = Napchart::default(); assert_eq!(chart.shape, ChartShape::Circle); let wide_chart = Napchart::default().shape(ChartShape::Wide); assert_eq!(wide_chart.shape, ChartShape::Wide);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Napchart
impl UnwindSafe for Napchart
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more