Skip to main content

Schema

Struct Schema 

Source
pub struct Schema {
    pub fields: Vec<Field>,
    pub lrecl_fixed: Option<u32>,
    pub tail_odo: Option<TailODO>,
    pub fingerprint: String,
}
Expand description

A parsed COBOL copybook schema

Fields§

§fields: Vec<Field>

Root fields in the schema

§lrecl_fixed: Option<u32>

Fixed record length (LRECL) if applicable

§tail_odo: Option<TailODO>

Tail ODO information if present

§fingerprint: String

Schema fingerprint for provenance tracking

Implementations§

Source§

impl Schema

Source

pub fn new() -> Self

Create a new empty schema

Source

pub fn from_fields(fields: Vec<Field>) -> Self

Create a schema from a list of fields

Source

pub fn calculate_fingerprint(&mut self)

Calculate the schema fingerprint using SHA-256

Source

pub fn create_canonical_json(&self) -> String

Create canonical JSON representation for fingerprinting

Source

pub fn find_field(&self, path: &str) -> Option<&Field>

Find a field by path

Looks up a field by its fully-qualified dotted path (e.g., "REC.ID"). Searches recursively through all nested groups.

§Examples
use copybook_core::parse_copybook;

let schema = parse_copybook("01 REC.\n   05 ID PIC 9(5).\n   05 NAME PIC X(20).").unwrap();

let field = schema.find_field("REC.ID").unwrap();
assert_eq!(field.name, "ID");
assert_eq!(field.len, 5);

assert!(schema.find_field("NONEXISTENT").is_none());
Source

pub fn find_field_or_alias(&self, name_or_path: &str) -> Option<&Field>

Find a field by path or RENAMES alias name

This method first tries to find a field by its path using standard lookup. If not found, it searches for a level-66 RENAMES field whose name matches the query and returns that alias field.

§Examples
let schema: Schema = // ... parsed schema with RENAMES

// Direct field lookup
if let Some(field) = schema.find_field_or_alias("CUSTOMER-INFO") {
    println!("Found field: {}", field.name);
}

// Alias lookup - finds level-66 field
if let Some(alias) = schema.find_field_or_alias("CUSTOMER-DETAILS") {
    if alias.level == 66 {
        println!("Found RENAMES alias: {}", alias.name);
    }
}
Source

pub fn resolve_alias_to_target(&self, name_or_path: &str) -> Option<&Field>

Resolve a RENAMES alias to its first target field

If the query matches a level-66 RENAMES alias, this method returns the first storage-bearing field covered by that alias (from resolved_renames.members). Otherwise, it performs standard field lookup.

This is useful for codec integration where you want to decode/encode data using an alias name but need the actual storage field.

§Examples
let schema: Schema = // ... parsed schema with RENAMES

// Resolve alias to target field
if let Some(target) = schema.resolve_alias_to_target("CUSTOMER-DETAILS") {
    // target will be CUSTOMER-INFO (or its first member)
    println!("Alias resolves to: {}", target.name);
}
Source

pub fn find_redefining_fields<'a>(&'a self, target_path: &str) -> Vec<&'a Field>

Find all fields that redefine the field at the given path

Returns a list of fields whose redefines_of points to target_path.

§Examples
use copybook_core::parse_copybook;

let schema = parse_copybook(
    "01 REC.\n   05 AMT-NUM PIC 9(5)V99.\n   05 AMT-TXT REDEFINES AMT-NUM PIC X(7)."
).unwrap();

let redefs = schema.find_redefining_fields("AMT-NUM");
assert_eq!(redefs.len(), 1);
assert_eq!(redefs[0].name, "AMT-TXT");
Source

pub fn all_fields(&self) -> Vec<&Field>

Get all fields in a flat list (pre-order traversal)

Returns every field in the schema, including nested children, as a flat vector in pre-order (depth-first) traversal order.

§Examples
use copybook_core::parse_copybook;

let schema = parse_copybook("01 REC.\n   05 ID PIC 9(5).\n   05 NAME PIC X(20).").unwrap();

let all = schema.all_fields();
assert_eq!(all.len(), 3); // REC group + 2 leaf fields
assert_eq!(all[0].name, "REC");
assert_eq!(all[1].name, "ID");
assert_eq!(all[2].name, "NAME");

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Schema

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Schema

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Schema

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,