Skip to main content

Editor

Struct Editor 

Source
pub struct Editor { /* private fields */ }
Expand description

One editable circuit plus its undo and redo history.

Implementations§

Source§

impl Editor

Source

pub fn new(circuit: Circuit) -> Self

Wrap an already-parsed circuit. The document starts clean and with an empty history.

Source

pub fn blank() -> Self

An empty document.

Source

pub fn circuit(&self) -> &Circuit

Source

pub fn is_dirty(&self) -> bool

Whether there are changes since the last Editor::mark_saved.

Source

pub fn mark_saved(&mut self)

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn transact<T>( &mut self, edit: impl FnOnce(&mut Circuit) -> Result<T, EditError>, ) -> Result<T, EditError>

Apply edit to a copy of the circuit and commit it only if it returns Ok. One call is one undo step.

Source

pub fn undo(&mut self) -> bool

Undo the last committed edit. False when the history is empty.

Source

pub fn redo(&mut self) -> bool

Re-apply the last undone edit. False when there is nothing to redo.

Source

pub fn add_part(&mut self, part: PartInstance) -> Result<(), EditError>

Source

pub fn remove_part(&mut self, id: &str) -> Result<usize, EditError>

Remove a part and every wire attached to it. Returns the number of wires removed as well.

Source

pub fn move_part( &mut self, id: &str, left: f64, top: f64, ) -> Result<(), EditError>

Move a part to a canvas position, snapped to the grid.

Source

pub fn set_attr( &mut self, id: &str, key: impl Into<String>, value: Value, ) -> Result<(), EditError>

Set one attribute, creating it if needed.

Source

pub fn connect( &mut self, from: PinRef, to: PinRef, color: Option<String>, ) -> Result<(), EditError>

Draw a wire. Duplicate pins and duplicate wires are refused.

Source

pub fn disconnect(&mut self, index: usize) -> Result<(), EditError>

Source

pub fn check(&self) -> Vec<Diagnostic>

Structural diagnostics. Electrical checks live in litz-board, which owns the runtime and the catalog.

Source

pub fn validate(&self, registry: &Registry) -> Vec<Diagnostic>

Validate against a catalog: unknown part types, pins that do not exist, and connections the schema forbids.

Source

pub fn to_json(&self) -> Result<String, EditError>

Serialize the document as diagram.json.

Source

pub fn from_json(text: &str) -> Result<Self, EditError>

Parse a document from diagram.json.

Trait Implementations§

Source§

impl Clone for Editor

Source§

fn clone(&self) -> Self

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 Editor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Editor

§

impl Freeze for Editor

§

impl Move for Editor

§

impl RefUnwindSafe for Editor

§

impl Send for Editor
where RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send,

§

impl Sync for Editor
where RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync,

§

impl Unpin for Editor
where *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin,

§

impl UnsafeUnpin for Editor

§

impl UnwindSafe for Editor
where RawVecInner: UnwindSafe, BTreeMap<String, Value>: UnwindSafe,

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
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.