Blaž Hrastnik 1 month ago
parent 8444f52e9a
commit e94735bbd3

@ -130,22 +130,21 @@ pub struct Buffer {
impl Buffer { impl Buffer {
/// Returns a Buffer with all cells set to the default one /// Returns a Buffer with all cells set to the default one
#[must_use]
pub fn empty(area: Rect) -> Buffer { pub fn empty(area: Rect) -> Buffer {
let cell: Cell = Default::default(); Buffer::filled(area, &Cell::default())
Buffer::filled(area, &cell)
} }
/// Returns a Buffer with all cells initialized with the attributes of the given Cell /// Returns a Buffer with all cells initialized with the attributes of the given Cell
#[must_use]
pub fn filled(area: Rect, cell: &Cell) -> Buffer { pub fn filled(area: Rect, cell: &Cell) -> Buffer {
let size = area.area(); let size = area.area();
let mut content = Vec::with_capacity(size); let content = vec![cell.clone(); size];
for _ in 0..size {
content.push(cell.clone());
}
Buffer { area, content } Buffer { area, content }
} }
/// Returns a Buffer containing the given lines /// Returns a Buffer containing the given lines
#[must_use]
pub fn with_lines<S>(lines: Vec<S>) -> Buffer pub fn with_lines<S>(lines: Vec<S>) -> Buffer
where where
S: AsRef<str>, S: AsRef<str>,

Loading…
Cancel
Save