pub struct DrawingStorage {
pub version: u32,
pub symbol: String,
pub timeframe: Option<String>,
pub drawings: Vec<StoredDrawing>,
pub metadata: StorageMetadata,
}Expand description
Drawing storage for saving/loading drawings
It is read only through Self::from_json, which checks the version,
migrates older files and loads each drawing on its own.
Fields§
§version: u32Format version, Self::CURRENT_VERSION once loaded
symbol: StringSymbol this storage is for
timeframe: Option<String>Timeframe (optional)
drawings: Vec<StoredDrawing>All stored drawings
metadata: StorageMetadataMetadata
Implementations§
Source§impl DrawingStorage
impl DrawingStorage
Sourcepub const CURRENT_VERSION: u32 = 6
pub const CURRENT_VERSION: u32 = 6
Current storage format version. Version 6 draws arrow marks in their own colour; earlier versions load in the colour they were drawn in. Version 5 gives Elliott double and triple combinations an unlabelled start point; earlier versions load with a start point on their first anchor. Version 4 draws brushes and highlighters at their stored width and opacity; earlier versions load at the width and opacity their strokes were drawn at. Version 3 preserves editable ray and extended-line extensions; versions 1 and 2 migrate to their former rendered reach when loaded.
Sourcepub fn with_timeframe(self, timeframe: impl Into<String>) -> Self
pub fn with_timeframe(self, timeframe: impl Into<String>) -> Self
Set timeframe
Sourcepub fn add_drawing(&mut self, drawing: StoredDrawing)
pub fn add_drawing(&mut self, drawing: StoredDrawing)
Add a drawing, or replace the drawing with the same id in place, so a
drawing saved again after an edit is stored once and the ids stay
unique, as Self::from_json requires. The replacement keeps the
position and the created_at of the drawing it replaces and takes
every other field, notes included, from drawing.
Sourcepub fn remove_drawing(&mut self, id: &str) -> bool
pub fn remove_drawing(&mut self, id: &str) -> bool
Remove a drawing by ID
Sourcepub fn get_drawing(&self, id: &str) -> Option<&StoredDrawing>
pub fn get_drawing(&self, id: &str) -> Option<&StoredDrawing>
Get a drawing by ID
Sourcepub fn get_drawing_mut(&mut self, id: &str) -> Option<&mut StoredDrawing>
pub fn get_drawing_mut(&mut self, id: &str) -> Option<&mut StoredDrawing>
Get a mutable drawing by ID
Sourcepub fn drawings(&self) -> &[StoredDrawing]
pub fn drawings(&self) -> &[StoredDrawing]
Get all drawings
Sourcepub fn to_json(&self) -> Result<String, SaveError>
pub fn to_json(&self) -> Result<String, SaveError>
Serialize to JSON, refusing what would lose a drawing on the next load:
a non-finite number, which JSON cannot store and which would otherwise be
written as null, an id an earlier drawing already has, a cursor tool
such as the eraser, an unsupported timestamp and fewer anchors than the tool draws with.
Self::from_json skips these records.
Sourcepub fn from_json(json: &str) -> Result<(Self, Vec<SkippedDrawing>), LoadError>
pub fn from_json(json: &str) -> Result<(Self, Vec<SkippedDrawing>), LoadError>
Deserialize from JSON, migrating versions 1 to 5 to the current format.
Fails as a whole with a LoadError: LoadError::Json for invalid JSON or a missing
or invalid version, symbol, timeframe or metadata, and LoadError::UnsupportedVersion
for a version this release does not know. A
drawing that cannot be read (a missing field, a null an earlier release
wrote for a non-finite number, a number out of the range of its field, a
tool type from a newer release, a cursor, fewer anchors than the tool
draws with or a setting out of bounds) is
left out and returned as a SkippedDrawing with its SkipReason, so one bad drawing does
not lose the others. A drawing whose id an
earlier loaded drawing already has is skipped too, so the loaded ids are
unique and the first one in the file wins. Saving the returned storage writes
only the drawings that loaded; keep the original file if the skipped
ones must be recovered. A drawing whose timeframe filter names no
timeframe loads as visible on every timeframe.
Trait Implementations§
Source§impl Clone for DrawingStorage
impl Clone for DrawingStorage
Source§fn clone(&self) -> DrawingStorage
fn clone(&self) -> DrawingStorage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DrawingStorage
impl Debug for DrawingStorage
Auto Trait Implementations§
impl Freeze for DrawingStorage
impl RefUnwindSafe for DrawingStorage
impl Send for DrawingStorage
impl Sync for DrawingStorage
impl Unpin for DrawingStorage
impl UnsafeUnpin for DrawingStorage
impl UnwindSafe for DrawingStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more