Skip to content

Commit

Permalink
move ty to reader, improve fs
Browse files Browse the repository at this point in the history
  • Loading branch information
emanueldima committed Feb 9, 2024
1 parent 943602e commit 17d2a28
Show file tree
Hide file tree
Showing 17 changed files with 384 additions and 303 deletions.
6 changes: 3 additions & 3 deletions src/base/elevation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn elevation_map(interpretation: &str) -> Res<Arc<IndexMap<&'static str, Elevate
}

pub(crate) fn top_interpretation(cell: &Cell) -> Option<&str> {
if cell.interpretation() == "fs" && cell.ty().ok()? == "fs" {
if cell.interpretation() == "fs" && cell.read().ty().ok()? == "fs" {
if let Ok(reader) = cell.read().err() {
if let Ok(Value::Str(name)) = reader.label() {
if name.ends_with(".c") {
Expand Down Expand Up @@ -171,13 +171,13 @@ impl ElevationGroup {
}
if let Ok(e) = elevation_map(old_interp) {
if let Some((_, target_interpretation, func)) = e.get_full(interp) {
debug!("elevate {} to {}", old_interp, key);
// debug!("elevate {} to {}", old_interp, key);
return func(self.0.clone(), target_interpretation);
}
}
if let Ok(e) = elevation_map("value") {
if let Some((_, target_interpretation, func)) = e.get_full(interp) {
debug!("elevate as value from {} to {}", old_interp, key);
// debug!("elevate as value from {} to {}", old_interp, key);
return func(self.0.clone(), target_interpretation);
}
}
Expand Down
26 changes: 13 additions & 13 deletions src/base/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@ impl std::fmt::Debug for HErr {
}

impl CellReaderTrait for HErr {
fn ty(&self) -> Res<&str> {
Ok(match self.kind {
HErrKind::None => "nores",
HErrKind::User => "user",
HErrKind::IO => "io",
HErrKind::Net => "net",
HErrKind::Internal => "internal",
HErrKind::ReadOnly => "readonly",
HErrKind::CannotLock => "cannotlock",
HErrKind::InvalidFormat => "invalidformat",
})
}

fn value(&self) -> Res<Value> {
Err(self.clone())
}
Expand Down Expand Up @@ -246,19 +259,6 @@ impl CellTrait for HErr {
"error"
}

fn ty(&self) -> Res<&str> {
Ok(match self.kind {
HErrKind::None => "nores",
HErrKind::User => "user",
HErrKind::IO => "io",
HErrKind::Net => "net",
HErrKind::Internal => "internal",
HErrKind::ReadOnly => "readonly",
HErrKind::CannotLock => "cannotlock",
HErrKind::InvalidFormat => "invalidformat",
})
}

fn read(&self) -> Res<Self::CellReader> {
Err(self.clone())
}
Expand Down
17 changes: 8 additions & 9 deletions src/base/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,20 @@ impl fmt::Debug for Cell {
}

impl CellReaderTrait for CellReader {
fn ty(&self) -> Res<&str> {
dispatch_dyn_cell_reader!(&self.0, |x| { x.ty() })
}
fn index(&self) -> Res<usize> {
dispatch_dyn_cell_reader!(&self.0, |x| { Ok(x.index()?) })
dispatch_dyn_cell_reader!(&self.0, |x| { x.index() })
}
fn label(&self) -> Res<Value> {
dispatch_dyn_cell_reader!(&self.0, |x| { Ok(x.label()?) })
dispatch_dyn_cell_reader!(&self.0, |x| { x.label() })
}
fn value(&self) -> Res<Value> {
dispatch_dyn_cell_reader!(&self.0, |x| { Ok(x.value()?) })
dispatch_dyn_cell_reader!(&self.0, |x| { x.value() })
}
fn serial(&self) -> Res<String> {
dispatch_dyn_cell_reader!(&self.0, |x| { Ok(x.serial()?) })
dispatch_dyn_cell_reader!(&self.0, |x| { x.serial() })
}
}
impl CellReader {
Expand Down Expand Up @@ -285,10 +288,6 @@ impl Cell {
.unwrap_or_else(Cell::from)
}

pub fn ty(&self) -> Res<&str> {
dispatch_dyn_cell!(&self.dyn_cell, |x| { x.ty() })
}

pub fn read(&self) -> CellReader {
let reader: DynCellReader = dispatch_dyn_cell!(&self.dyn_cell, |x| {
match x.read() {
Expand Down Expand Up @@ -328,7 +327,7 @@ impl Cell {
let sub = dispatch_dyn_cell!(&self.dyn_cell, |x| {
match x.sub() {
Ok(r) => DynGroup::from(r),
Err(e) => DynGroup::from(e),
Err(e) => DynGroup::from(e.with_path(self.path().unwrap_or_default())),
}
});
Group {
Expand Down
10 changes: 5 additions & 5 deletions src/base/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ impl CellTrait for FieldCell {
self.cell.interpretation()
}

fn ty(&self) -> Res<&str> {
Ok("field")
}

fn read(&self) -> Res<FieldReader> {
Ok(FieldReader {
cell: self.cell.clone(),
Expand All @@ -154,11 +150,15 @@ impl CellTrait for FieldCell {
}

impl CellReaderTrait for FieldReader {
fn ty(&self) -> Res<&str> {
Ok("field")
}

fn value(&self) -> Res<Value> {
match self.ty {
FieldType::Value => self.reader.value(),
FieldType::Label => self.reader.label(),
FieldType::Type => Ok(Value::Str(self.cell.ty()?)),
FieldType::Type => self.reader.ty().map(Value::Str),
FieldType::Index => Ok(Value::from(self.reader.index()? as u64)),
FieldType::Serial => self
.serial
Expand Down
7 changes: 6 additions & 1 deletion src/base/intra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub trait CellTrait: Clone + Debug {
type CellWriter: CellWriterTrait;

fn interpretation(&self) -> &str;
fn ty(&self) -> Res<&str>;

fn read(&self) -> Res<Self::CellReader>;
fn write(&self) -> Res<Self::CellWriter>;
Expand All @@ -25,6 +24,8 @@ pub trait CellTrait: Clone + Debug {
}

pub trait CellReaderTrait: Debug {
fn ty(&self) -> Res<&str>;

fn index(&self) -> Res<usize>;

fn label(&self) -> Res<Value>;
Expand All @@ -35,6 +36,10 @@ pub trait CellReaderTrait: Debug {
}

pub trait CellWriterTrait: Debug {
fn set_ty(&mut self, new_type: &str) -> Res<()> {
todo!() // TODO: remove this default implementation
}

fn set_index(&mut self, value: OwnValue) -> Res<()> {
todo!() // TODO: remove this default implementation
}
Expand Down
Loading

0 comments on commit 17d2a28

Please sign in to comment.