Struct Proto

Source
pub struct Proto { /* private fields */ }
Expand description

Main structure representing a complete Protocol Buffer file. Contains all the elements that can be defined in a proto file.

Implementations§

Source§

impl Proto

Source

pub fn parse_file(path: &str) -> Result<String, ParserError>

Parses a proto file from the filesystem and returns its JSON representation.

§Arguments
  • path - Path to the proto file to be parsed
§Returns

A Result containing either the JSON string representation of the parsed proto file or a ParserError if any error occurs during parsing or processing.

§Examples
use proto_file_parser::Proto;

let json = Proto::parse_file("example.proto").unwrap();
println!("{}", json);
Source

pub fn parse(input: &str) -> Result<String, ParserError>

Parses a proto definition from a string and returns its JSON representation.

§Arguments
  • input - String containing the proto definition to be parsed
§Returns

A Result containing either the JSON string representation of the parsed proto definition or a ParserError if any error occurs during parsing or processing.

§Examples
use proto_file_parser::Proto;

let input = r#"
    syntax = "proto3";
    message Test {
        string name = 1;
    }
"#;

let json = Proto::parse(input).unwrap();
println!("{}", json);

Trait Implementations§

Source§

impl Debug for Proto

Source§

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

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

impl Serialize for Proto

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§

§

impl Freeze for Proto

§

impl RefUnwindSafe for Proto

§

impl Send for Proto

§

impl Sync for Proto

§

impl Unpin for Proto

§

impl UnwindSafe for Proto

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, 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, 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.