Skip to main content

TouchstoneError

Enum TouchstoneError 

Source
#[non_exhaustive]
pub enum TouchstoneError {
Show 20 variants Parse { context: TouchstoneErrorContext, source: Box<TouchstoneError>, }, Io(Error), InvalidUtf8(Utf8Error), MissingFileType { source_name: String, }, UnsupportedFileType { file_type: String, }, InvalidPortCount { file_type: String, }, MultipleOptionLines, InvalidDataLineParts { expected: usize, actual: usize, }, InvalidNumber { token: String, }, UnsupportedFrequencyUnit { unit: String, }, UnsupportedFormat { format: String, }, InvalidKeywordLine { line: String, }, UnsupportedVersion { version: String, }, InvalidNumberOfPorts { value: String, }, NumberOfPortsMismatch { keyword_ports: i32, extension_ports: i32, }, TwoPortDataOrderForNonTwoPort, UnsupportedTwoPortDataOrder { order: String, }, InvalidNumberOfFrequencies { value: String, }, NumberOfFrequenciesMismatch { expected: usize, actual: usize, }, UnsupportedMatrixFormat { format: String, },
}
Expand description

Error returned when Touchstone data cannot be read or parsed.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Parse

A parse error with source-location context.

Fields

§context: TouchstoneErrorContext

Source location where the parser detected the error.

§source: Box<TouchstoneError>

Structured root error.

§

Io(Error)

The source file could not be read.

§

InvalidUtf8(Utf8Error)

In-memory bytes were not valid UTF-8 Touchstone text.

§

MissingFileType

The source name did not include a file extension.

Fields

§source_name: String

Source name used for extension inference.

§

UnsupportedFileType

The source extension is not a supported Touchstone file type.

Fields

§file_type: String

Unsupported extension without the leading dot.

§

InvalidPortCount

The Touchstone extension did not contain a valid port count.

Fields

§file_type: String

Extension that could not be converted to a port count.

§

MultipleOptionLines

The file contained more than one option line.

§

InvalidDataLineParts

A data line did not contain the expected number of values.

Fields

§expected: usize

Number of values required for the current network rank.

§actual: usize

Number of values found in the line.

§

InvalidNumber

A numeric token could not be parsed as f64.

Fields

§token: String

Token that failed numeric parsing.

§

UnsupportedFrequencyUnit

The frequency unit is not supported.

Fields

§unit: String

Unit token from the option line.

§

UnsupportedFormat

The network data format is not supported.

Fields

§format: String

Format token from the option line.

§

InvalidKeywordLine

A keyword line was malformed.

Fields

§line: String

Full keyword line.

§

UnsupportedVersion

The Touchstone version is not supported.

Fields

§version: String

Version string from the [Version] keyword.

§

InvalidNumberOfPorts

The [Number of Ports] value was not a valid integer.

Fields

§value: String

Raw value from the keyword.

§

NumberOfPortsMismatch

The [Number of Ports] value did not match the source extension.

Fields

§keyword_ports: i32

Port count declared by the keyword.

§extension_ports: i32

Port count inferred from the source extension.

§

TwoPortDataOrderForNonTwoPort

[Two-Port Data Order] was present for a network other than .s2p.

§

UnsupportedTwoPortDataOrder

The [Two-Port Data Order] value is not supported.

Fields

§order: String

Order token from the keyword.

§

InvalidNumberOfFrequencies

The [Number of Frequencies] value was not a valid integer.

Fields

§value: String

Raw value from the keyword.

§

NumberOfFrequenciesMismatch

The parsed data line count did not match [Number of Frequencies].

Fields

§expected: usize

Expected number of frequency rows.

§actual: usize

Parsed number of frequency rows.

§

UnsupportedMatrixFormat

Matrix format values other than Full are not supported.

Fields

§format: String

Matrix format token from the keyword.

Implementations§

Source§

impl TouchstoneError

Source

pub fn context(&self) -> Option<&TouchstoneErrorContext>

Return parser source-location context when this error has it.

§Examples
let error =
    touchstone::Network::from_str("uploaded.s1p", "# GHz S RI R 50\n1.0 0.1\n")
        .unwrap_err();

let context = error.context().unwrap();
assert_eq!(context.source_name, "uploaded.s1p");
assert_eq!(context.line_number, Some(2));
assert_eq!(context.line.as_deref(), Some("1.0 0.1"));
Source

pub fn root_cause(&self) -> &TouchstoneError

Return the deepest structured error wrapped by parser context.

§Examples
use touchstone::{Network, TouchstoneError};

let error = Network::from_str("uploaded.s1p", "# GHz S RI R 50\n1.0 0.1\n").unwrap_err();

assert!(matches!(
    error.root_cause(),
    TouchstoneError::InvalidDataLineParts {
        expected: 3,
        actual: 2
    }
));

Trait Implementations§

Source§

impl Debug for TouchstoneError

Source§

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

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

impl Display for TouchstoneError

Source§

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

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

impl Error for TouchstoneError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for TouchstoneError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Utf8Error> for TouchstoneError

Source§

fn from(err: Utf8Error) -> Self

Converts to this type from the input type.

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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