Skip to content

Commit

Permalink
reorganized into /api,/api/internal,etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
emanueldima committed Mar 8, 2024
1 parent c470e23 commit 8273dcc
Show file tree
Hide file tree
Showing 49 changed files with 348 additions and 193 deletions.
1 change: 0 additions & 1 deletion doc/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
- support diff ./file.json^json^tree ./file.xml^xml^tree
- '**[filter]' must be work as '**/*[filter]' (filter to be applied only on leaves)
- support rust/ts write: `hial './src/tests/rust.rs^rust/*[:function_item].label = "modified_fn_name"'`
- new structure: /api, /api/impl, /interpretations/api, /interpretations/*, /search
- add http interpretation params: method=HEAD, accept=""
- functions
- should blobs/bytes be part of value? they are only useful by reinterpretation
Expand Down
2 changes: 1 addition & 1 deletion examples/print_capi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hiallib::base::*;
use hiallib::api::*;
// use hiallib::c_api::*;
// use std::ffi::CString;

Expand Down
2 changes: 1 addition & 1 deletion examples/print_rust.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hiallib::base::*;
use hiallib::api::*;
use hiallib::pprint::pprint;

// examples = "."^file/examples;
Expand Down
85 changes: 1 addition & 84 deletions src/base/error.rs → src/api/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cell::OnceCell, error::Error, fmt, rc::Rc};

use crate::{base::*, warning};
use crate::warning;

pub type Res<T> = Result<T, HErr>;

Expand Down Expand Up @@ -213,89 +213,6 @@ 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())
}

fn label(&self) -> Res<Value> {
Err(self.clone())
}

fn index(&self) -> Res<usize> {
Err(self.clone())
}

fn serial(&self) -> Res<String> {
Err(self.clone())
}
}

impl CellWriterTrait for HErr {
fn value(&mut self, value: OwnValue) -> Res<()> {
Err(self.clone())
}
}

impl CellTrait for HErr {
type Group = HErr;
type CellReader = HErr;
type CellWriter = HErr;

fn interpretation(&self) -> &str {
"error"
}

fn read(&self) -> Res<Self::CellReader> {
Err(self.clone())
}

fn write(&self) -> Res<Self::CellWriter> {
Err(self.clone())
}

fn head(&self) -> Res<(Self, Relation)> {
nores()
}
}

impl GroupTrait for HErr {
type Cell = HErr;
type CellIterator = std::iter::Empty<Res<HErr>>;

fn label_type(&self) -> LabelType {
LabelType {
is_indexed: false,
unique_labels: true,
}
}

fn len(&self) -> Res<usize> {
Ok(0)
}

fn at(&self, index: usize) -> Res<Self::Cell> {
Err(self.clone())
}

fn get_all(&self, label: Value<'_>) -> Res<Self::CellIterator> {
Err(self.clone())
}
}

pub(crate) fn capture_stack_trace() -> Box<[String]> {
let backtrace = format!("{}", std::backtrace::Backtrace::capture());
let mut frames = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/base/elevation.rs → src/api/internal/elevation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{sync::Arc, sync::RwLock};

use indexmap::IndexMap;

use crate::{base::*, debug, guard_ok, guard_some, warning};
use crate::{api::interpretation::*, api::*, debug, guard_ok, guard_some, warning};

use linkme::distributed_slice;

Expand Down
84 changes: 84 additions & 0 deletions src/api/internal/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::{api::interpretation::*, api::*};

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())
}

fn label(&self) -> Res<Value> {
Err(self.clone())
}

fn index(&self) -> Res<usize> {
Err(self.clone())
}

fn serial(&self) -> Res<String> {
Err(self.clone())
}
}

impl CellWriterTrait for HErr {
fn set_value(&mut self, value: OwnValue) -> Res<()> {
Err(self.clone())
}
}

impl CellTrait for HErr {
type Group = HErr;
type CellReader = HErr;
type CellWriter = HErr;

fn interpretation(&self) -> &str {
"error"
}

fn read(&self) -> Res<Self::CellReader> {
Err(self.clone())
}

fn write(&self) -> Res<Self::CellWriter> {
Err(self.clone())
}

fn head(&self) -> Res<(Self, Relation)> {
nores()
}
}

impl GroupTrait for HErr {
type Cell = HErr;
type CellIterator = std::iter::Empty<Res<HErr>>;

fn label_type(&self) -> LabelType {
LabelType {
is_indexed: false,
unique_labels: true,
}
}

fn len(&self) -> Res<usize> {
Ok(0)
}

fn at(&self, index: usize) -> Res<Self::Cell> {
Err(self.clone())
}

fn get_all(&self, label: Value<'_>) -> Res<Self::CellIterator> {
Err(self.clone())
}
}
22 changes: 17 additions & 5 deletions src/base/field.rs → src/api/internal/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
///
use std::{cell::OnceCell, rc::Rc};

use crate::base::*;
use crate::{api::interpretation::*, api::*};

#[repr(u8)]
#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -185,13 +185,25 @@ impl CellReaderTrait for FieldReader {
}

impl CellWriterTrait for FieldWriter {
fn value(&mut self, value: OwnValue) -> Res<()> {
fn set_value(&mut self, value: OwnValue) -> Res<()> {
match self.ty {
FieldType::Value => self.writer.value(value),
FieldType::Label => self.writer.label(value),
FieldType::Type => userres("cannot change cell type"),
FieldType::Index => self.writer.set_index(value),
FieldType::Serial => self.writer.set_serial(value),
FieldType::Type => {
if let OwnValue::String(t) = value {
self.writer.ty(t.as_str())
} else {
userres("set type argument must be a string")
}
}
FieldType::Index => {
if let OwnValue::Int(i) = value {
self.writer.index(i.as_i128() as usize)
} else {
userres("set type argument must be a string")
}
}
FieldType::Serial => self.writer.serial(value),
}
}
}
3 changes: 3 additions & 0 deletions src/api/internal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod elevation;
pub mod error;
pub mod field;
8 changes: 4 additions & 4 deletions src/base/intra.rs → src/api/interpretation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fmt::Debug, marker::PhantomData};

use crate::base::*;
use crate::api::*;

pub trait CellTrait: Clone + Debug {
type Group: GroupTrait;
Expand Down Expand Up @@ -40,15 +40,15 @@ pub trait CellWriterTrait: Debug {
todo!() // TODO: remove this default implementation
}

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

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

fn value(&mut self, value: OwnValue) -> Res<()>;
fn set_value(&mut self, value: OwnValue) -> Res<()>;

fn set_serial(&mut self, value: OwnValue) -> Res<()> {
todo!() // TODO: remove this default implementation
Expand Down
15 changes: 15 additions & 0 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
mod error;
mod internal;
pub mod interpretation;
mod relation;
mod selector;
mod value;
mod xell;

pub use error::*;
pub use relation::*;
pub use selector::*;
pub use value::*;
pub use xell::*;

pub use internal::elevation::{ElevationConstructor, ELEVATION_CONSTRUCTORS};
File renamed without changes.
2 changes: 1 addition & 1 deletion src/base/selector.rs → src/api/selector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::base::value::*;
use crate::api::value::*;
use core::fmt::{self, Display};
use std::borrow::Borrow;

Expand Down
File renamed without changes.
Loading

0 comments on commit 8273dcc

Please sign in to comment.