Skip to content

Commit

Permalink
Implement Clone for Buffer and use Arc::make_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpot51 committed Dec 20, 2023
1 parent c9a2685 commit 90bcfcf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
15 changes: 15 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ pub struct Buffer {
scratch: ShapeBuffer,
}

impl Clone for Buffer {
fn clone(&self) -> Self {
Self {
lines: self.lines.clone(),
metrics: self.metrics,
width: self.width,
height: self.height,
scroll: self.scroll,
redraw: self.redraw,
wrap: self.wrap,
scratch: ShapeBuffer::default(),
}
}
}

impl Buffer {
/// Create an empty [`Buffer`] with the provided [`Metrics`].
/// This is useful for initializing a [`Buffer`] without a [`FontSystem`].
Expand Down
2 changes: 1 addition & 1 deletion src/buffer_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloc::{string::String, vec::Vec};
use crate::{Align, AttrsList, FontSystem, LayoutLine, ShapeBuffer, ShapeLine, Shaping, Wrap};

/// A line (or paragraph) of text that is shaped and laid out
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct BufferLine {
//TODO: make this not pub(crate)
text: String,
Expand Down
6 changes: 1 addition & 5 deletions src/edit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,7 @@ pub trait Edit<'buffer> {
match self.buffer_ref_mut() {
BufferRef::Owned(buffer) => f(buffer),
BufferRef::Borrowed(buffer) => f(buffer),
BufferRef::Arc(arc) => match Arc::get_mut(arc) {
Some(buffer) => f(buffer),
//TODO: use make_mut?
None => panic!("BufferRef::Arc cannot be accessed mutibly"),
},
BufferRef::Arc(buffer) => f(Arc::make_mut(buffer)),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn shape_skip(
}

/// A shaped glyph
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct ShapeGlyph {
pub start: usize,
pub end: usize,
Expand Down Expand Up @@ -423,7 +423,7 @@ impl ShapeGlyph {
}

/// A shaped word (for word wrapping)
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct ShapeWord {
pub blank: bool,
pub glyphs: Vec<ShapeGlyph>,
Expand Down Expand Up @@ -527,7 +527,7 @@ impl ShapeWord {
}

/// A shaped span (for bidirectional processing)
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct ShapeSpan {
pub level: unicode_bidi::Level,
pub words: Vec<ShapeWord>,
Expand Down Expand Up @@ -638,7 +638,7 @@ impl ShapeSpan {
}

/// A shaped line (or paragraph)
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct ShapeLine {
pub rtl: bool,
pub spans: Vec<ShapeSpan>,
Expand Down

0 comments on commit 90bcfcf

Please sign in to comment.