Struct brane_ast::edgebuffer::EdgeBuffer
source · pub struct EdgeBuffer { /* private fields */ }
Expand description
Defines an EdgeBuffer, which is a muteable buffer to which we can compile edges.
Every buffer may be thought of as a single ‘stream’ of operations. If it branches for whatever reason, typically, multiple EdgeBuffers are involved the define each of the streams.
Because an EdgeBuffer is a single stream, it is implemented as a LinkedList of edges. Any branch is represented as links to other buffers.
Implementations§
source§impl EdgeBuffer
impl EdgeBuffer
sourcepub fn new() -> EdgeBuffer
pub fn new() -> EdgeBuffer
Constructor for the EdgeBuffer that initializes it to empty.
§Returns
An EdgeBufferPtr that refers to the newly instantiated object.
sourcepub fn write(&mut self, edge: Edge)
pub fn write(&mut self, edge: Edge)
Adds a new edge to the end of this EdgeBuffer.
Note that the function itself is agnostic to the specific kind of edge. The only requirement is that, when using EdgeBuffer::write()
, the last edge in the buffer can linearly connect to this one. Be aware of this when writing non-Linear edges using this function.
§Arguments
edge
: The Edge to append.
§Returns
Nothing, but does add it internally.
sourcepub fn insert_at_end(&mut self, edge: Edge)
pub fn insert_at_end(&mut self, edge: Edge)
Adds a new edge to the end of this EdgeBuffer, although it is added before any stop/return/jump whatever.
Note that the function itself is agnostic to the specific kind of edge. The only requirement is that, when using EdgeBuffer::write()
, the last non-returning edge in the buffer can linearly connect to this one. Be aware of this when writing non-Linear edges using this function.
§Arguments
edge
: The Edge to append.
§Returns
Nothing, but does add it internally.
sourcepub fn write_jump(&mut self, target: EdgeBufferNodePtr)
pub fn write_jump(&mut self, target: EdgeBufferNodePtr)
Adds a new (linear) edge to the end of this EdgeBuffer, but one that loops back to an earlier point in the buffer.
Note that the function itself is agnostic to the specific kind of edge. The only requirement is that, when using EdgeBuffer::write()
, the last edge in the buffer can linearly connect to this one. Be aware of this when writing non-Linear edges using this function.
§Arguments
edge
: The Edge to append.target
: The EdgeNode to wrap back to.
§Returns
Nothing, but does add it internally.
sourcepub fn write_branch(
&mut self,
true_branch: Option<EdgeBuffer>,
false_branch: Option<EdgeBuffer>,
)
pub fn write_branch( &mut self, true_branch: Option<EdgeBuffer>, false_branch: Option<EdgeBuffer>, )
Adds a new branch to the end of this EdgeBuffer.
It will automatically be appended by an empty linear node that marks the ‘joining’ node of the Branch, unless there is a true and a false branch and both are returning (i.e., feature a return-branch in all paths).
Note that the function requires that the top edge on the buffer is linearly connectible. However, as a tradeoff, it also makes sure that it always is (as long as it doesn’t return).
§Arguments
true_branch
: The Edges to take when the branch is taken (if any).false_branch
: The Edges to take when the branch is not taken (if any).
§Returns
Nothing, but does append the buffer with a new branch structure.
sourcepub fn write_parallel(
&mut self,
branches: Vec<EdgeBuffer>,
merge: MergeStrategy,
)
pub fn write_parallel( &mut self, branches: Vec<EdgeBuffer>, merge: MergeStrategy, )
Adds a new parallel to the end of this EdgeBuffer.
It will automatically be appended by a join.
Note that the function requires that the top edge on the buffer is linearly connectible. However, as a tradeoff, it also makes sure that it always is after this call.
§Arguments
branches
: The Edges that represent each of the branches to run in parallel.merge
: The MergeStrategy that the generated join-edge needs to implement.
§Returns
Nothing, but does append the buffer with a new parallel structure.
sourcepub fn write_loop(&mut self, condition: EdgeBuffer, consequence: EdgeBuffer)
pub fn write_loop(&mut self, condition: EdgeBuffer, consequence: EdgeBuffer)
Adds a new loop to the end of this EdgeBuffer.
It will automatically be appended by a ‘next edge to take’.
Note that the function requires that the top edge on the buffer is linearly connectible. However, as a tradeoff, it also makes sure that it always is after this call.
§Arguments
condition
: The Edges that represent the condition computation.consequence
: The body of Edges that are actually repeated.
§Returns
Nothing, but does append the buffer with a new loop structure.
sourcepub fn write_end(&mut self)
pub fn write_end(&mut self)
Adds a new end connection to the end of this EdgeBuffer.
Note that the function requires that the top edge on the buffer is linearly connectible. Because an end doesn’t connect, that means no EdgeBuffer::write*()
can be used again.
§Arguments
end_edge
: The edge that forms the actual end node. May be anything that linearly connects.
§Returns
Nothing, but does append the buffer with a new end structure.
sourcepub fn write_stop(&mut self, stop_edge: Edge)
pub fn write_stop(&mut self, stop_edge: Edge)
Adds a new stop to the end of this EdgeBuffer.
Note that the function requires that the top edge on the buffer is linearly connectible. Because an end doesn’t connect, that means no EdgeBuffer::write*()
can be used again.
§Arguments
stop_edge
: The edge that forms the actual end node. May only be ’Edge::Returnor
Edge::Stop`.
§Returns
Nothing, but does append the buffer with a new end structure.
sourcepub fn append(&mut self, other: EdgeBuffer)
pub fn append(&mut self, other: EdgeBuffer)
sourcepub fn merge_linear(&mut self)
pub fn merge_linear(&mut self)
Merges all of the consecutive linear edges in this buffer to one edge.
§Returns
Nothing, but does merge some edges if they are consecutive and linear.
sourcepub fn fully_returns(&self) -> bool
pub fn fully_returns(&self) -> bool
Helper function that traverses the EdgeBuffer to see if it fully returns.
§Returns
Whether or not this buffer fully returns (true) or not (false).
sourcepub fn start(&self) -> &Option<EdgeBufferNodePtr>
pub fn start(&self) -> &Option<EdgeBufferNodePtr>
Returns the start node of the EdgeBuffer, if any. This may be used for iteration.
Trait Implementations§
source§impl Clone for EdgeBuffer
impl Clone for EdgeBuffer
source§fn clone(&self) -> EdgeBuffer
fn clone(&self) -> EdgeBuffer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for EdgeBuffer
impl Debug for EdgeBuffer
source§impl Default for EdgeBuffer
impl Default for EdgeBuffer
source§impl From<&EdgeBufferNodePtr> for EdgeBuffer
impl From<&EdgeBufferNodePtr> for EdgeBuffer
source§fn from(value: &EdgeBufferNodePtr) -> Self
fn from(value: &EdgeBufferNodePtr) -> Self
source§impl From<EdgeBufferNodePtr> for EdgeBuffer
impl From<EdgeBufferNodePtr> for EdgeBuffer
source§fn from(value: EdgeBufferNodePtr) -> Self
fn from(value: EdgeBufferNodePtr) -> Self
Auto Trait Implementations§
impl Freeze for EdgeBuffer
impl !RefUnwindSafe for EdgeBuffer
impl !Send for EdgeBuffer
impl !Sync for EdgeBuffer
impl Unpin for EdgeBuffer
impl !UnwindSafe for EdgeBuffer
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request