Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Created March 11, 2020 07:42
Show Gist options
  • Save andoriyu/85b6734c7ca4805fd738622af8e9574f to your computer and use it in GitHub Desktop.
Save andoriyu/85b6734c7ca4805fd738622af8e9574f to your computer and use it in GitHub Desktop.
pub struct Connection {
#[ucl(default = "420")]
port: i64,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Connection {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match *self {
Connection {
port: ref __self_0_0,
} => {
let mut debug_trait_builder = f.debug_struct("Connection");
let _ = debug_trait_builder.field("port", &&(*__self_0_0));
debug_trait_builder.finish()
}
}
}
}
impl ::std::convert::TryFrom<&::uclicious::ObjectRef> for Connection {
type Error = ::uclicious::ObjectError;
fn try_from(root: &::uclicious::ObjectRef) -> ::std::result::Result<Self, Self::Error> {
Ok(Connection {
port: match root.lookup_path("port") {
Some(obj) => ::std::convert::TryInto::try_into(obj)?,
None => 420,
},
})
}
}
impl ::std::convert::TryFrom<::uclicious::ObjectRef> for Connection {
type Error = ::uclicious::ObjectError;
fn try_from(source: ::uclicious::ObjectRef) -> ::std::result::Result<Self, Self::Error> {
::std::convert::TryInto::try_into(&source)
}
}
impl ::std::convert::TryFrom<::uclicious::Object> for Connection {
type Error = ::uclicious::ObjectError;
fn try_from(source: ::uclicious::Object) -> ::std::result::Result<Self, Self::Error> {
let obj: &::uclicious::ObjectRef = ::std::borrow::Borrow::borrow(&source);
::std::convert::TryInto::try_into(obj)
}
}
impl Connection {
pub fn builder() -> ConnectionBuilder {
ConnectionBuilder::default()
}
pub fn builder_with_parser(parser: ::uclicious::Parser) -> ConnectionBuilder {
ConnectionBuilder { __parser: parser }
}
}
pub struct ConnectionBuilder {
__parser: ::uclicious::Parser,
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::default::Default for ConnectionBuilder {
#[inline]
fn default() -> ConnectionBuilder {
ConnectionBuilder {
__parser: ::core::default::Default::default(),
}
}
}
#[allow(dead_code)]
impl ConnectionBuilder {
pub fn add_chunk_full<C: ::std::convert::AsRef<str>>(
&mut self,
chunk: C,
priority: ::uclicious::Priority,
strategy: ::uclicious::DuplicateStrategy,
) -> ::std::result::Result<(), ::uclicious::UclError> {
self.__parser.add_chunk_full(chunk, priority, strategy)
}
pub fn add_file_full<F: ::std::convert::AsRef<::std::path::Path>>(
&mut self,
file: F,
priority: ::uclicious::Priority,
strategy: ::uclicious::DuplicateStrategy,
) -> ::std::result::Result<(), ::uclicious::UclError> {
self.__parser.add_file_full(file, priority, strategy)
}
pub fn build(
mut self,
) -> ::std::result::Result<Connection, ::std::boxed::Box<dyn ::std::error::Error>> {
let root = self
.__parser
.get_object()
.map_err(::uclicious::UclError::boxed)?;
::std::convert::TryInto::try_into(root).map_err(::uclicious::ObjectError::boxed)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment