Skip to main content

DrawingStorage

Struct DrawingStorage 

Source
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: u32

Format version, Self::CURRENT_VERSION once loaded

§symbol: String

Symbol this storage is for

§timeframe: Option<String>

Timeframe (optional)

§drawings: Vec<StoredDrawing>

All stored drawings

§metadata: StorageMetadata

Metadata

Implementations§

Source§

impl DrawingStorage

Source

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.

Source

pub fn new(symbol: impl Into<String>) -> Self

Create new storage for a symbol

Source

pub fn with_timeframe(self, timeframe: impl Into<String>) -> Self

Set timeframe

Source

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.

Source

pub fn remove_drawing(&mut self, id: &str) -> bool

Remove a drawing by ID

Source

pub fn get_drawing(&self, id: &str) -> Option<&StoredDrawing>

Get a drawing by ID

Source

pub fn get_drawing_mut(&mut self, id: &str) -> Option<&mut StoredDrawing>

Get a mutable drawing by ID

Source

pub fn drawings(&self) -> &[StoredDrawing]

Get all drawings

Source

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.

Source

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.

Source

pub fn clear(&mut self)

Clear all drawings

Trait Implementations§

Source§

impl Clone for DrawingStorage

Source§

fn clone(&self) -> DrawingStorage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DrawingStorage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for DrawingStorage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.