Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust: add support for no_std env #205

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lib/xdrgen/generators/rust.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def render_top_matter(out)
// #{@output.relative_source_paths.join("\n// ")}
EOS
out.break
out.puts "#![allow(clippy::missing_errors_doc, clippy::unreadable_literal)]"
out.puts "#![allow(clippy::missing_errors_doc, clippy::unreadable_literal, clippy::needless_question_mark)]"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not modify the relevant code, so I am not sure why clippy is giving a warning. And I encountered some difficulties in fixing this warning, so let's add it first.

out.break
source_paths_sha256_hashes = @output.relative_source_path_sha256_hashes
out.puts <<-EOS.strip_heredoc
Expand Down Expand Up @@ -175,7 +175,7 @@ def render_enum_of_all_types(out, types)
pub const VARIANTS: [TypeVariant; #{types.count}] = [ #{types.map { |t| "TypeVariant::#{t}," }.join("\n")} ];
pub const VARIANTS_STR: [&'static str; #{types.count}] = [ #{types.map { |t| "\"#{t}\"," }.join("\n")} ];

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
#[allow(clippy::too_many_lines)]
pub fn read_xdr<R: Read>(v: TypeVariant, r: &mut Limited<R>) -> Result<Self> {
match v {
Expand All @@ -190,7 +190,7 @@ def render_enum_of_all_types(out, types)
Ok(t)
}

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
pub fn read_xdr_to_end<R: Read>(v: TypeVariant, r: &mut Limited<R>) -> Result<Self> {
let s = Self::read_xdr(v, r)?;
// Check that any further reads, such as this read of one byte, read no
Expand Down Expand Up @@ -234,7 +234,7 @@ def render_enum_of_all_types(out, types)
}
}

#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
pub fn from_xdr<B: AsRef<[u8]>>(v: TypeVariant, bytes: B, limits: Limits) -> Result<Self> {
let mut cursor = Limited::new(Cursor::new(bytes.as_ref()), limits);
let t = Self::read_xdr_to_end(v, &mut cursor)?;
Expand Down Expand Up @@ -318,7 +318,7 @@ def render_enum_of_all_types(out, types)
}

impl WriteXdr for Type {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
#[allow(clippy::too_many_lines)]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<()> {
match self {
Expand Down Expand Up @@ -407,7 +407,7 @@ def render_struct(out, struct)
out.puts ""
out.puts <<-EOS.strip_heredoc
impl ReadXdr for #{name struct} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self> {
r.with_limited_depth(|r| {
Ok(Self{
Expand All @@ -420,7 +420,7 @@ def render_struct(out, struct)
}

impl WriteXdr for #{name struct} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<()> {
w.with_limited_depth(|w| {
#{struct.members.map do |m|
Expand Down Expand Up @@ -517,7 +517,7 @@ def render_enum(out, enum)
}

impl ReadXdr for #{name enum} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self> {
r.with_limited_depth(|r| {
let e = i32::read_xdr(r)?;
Expand All @@ -528,7 +528,7 @@ def render_enum(out, enum)
}

impl WriteXdr for #{name enum} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<()> {
w.with_limited_depth(|w| {
let i: i32 = (*self).into();
Expand Down Expand Up @@ -656,7 +656,7 @@ def render_union(out, union)
impl Union<#{discriminant_type}> for #{name union} {}

impl ReadXdr for #{name union} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self> {
r.with_limited_depth(|r| {
let dv: #{discriminant_type} = <#{discriminant_type} as ReadXdr>::read_xdr(r)?;
Expand All @@ -678,7 +678,7 @@ def render_union(out, union)
}

impl WriteXdr for #{name union} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<()> {
w.with_limited_depth(|w| {
self.discriminant().write_xdr(w)?;
Expand Down Expand Up @@ -816,7 +816,7 @@ def render_typedef(out, typedef)
}

impl ReadXdr for #{name typedef} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self> {
r.with_limited_depth(|r| {
let i = #{reference_to_call(typedef, typedef.type)}::read_xdr(r)?;
Expand All @@ -827,7 +827,7 @@ def render_typedef(out, typedef)
}

impl WriteXdr for #{name typedef} {
#[cfg(feature = "std")]
#[cfg(feature = "alloc")]
fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<()> {
w.with_limited_depth(|w|{ self.0.write_xdr(w) })
}
Expand Down
Loading
Loading