Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
55 changes: 33 additions & 22 deletions autorust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion autorust/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ comrak = "0.54"
serde = "1"
http-types = "2"
once_cell = "1"
syn = { version = "2", features = ["parsing"] }
syn = { version = "3", features = ["parsing"] }
camino = "1"
askama = "0.16"
toml = "1.1"
Expand Down
21 changes: 14 additions & 7 deletions autorust/codegen/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use syn::{
punctuated::Punctuated,
token::{Gt, Impl, Lt},
AngleBracketedGenericArguments, GenericArgument, Path, PathArguments, PathSegment, TraitBound,
TraitBoundModifier, Type, TypeImplTrait, TypeParamBound, TypePath, TypeReference,
TraitBoundModifiers, Type, TypeImplTrait, TypeParamBound, TypePath, TypeReference,
};

/// code generation context
Expand Down Expand Up @@ -299,21 +299,22 @@ impl TypeNameCode {
if self.allow_qualify_models && self.qualify_models {
tp.path.segments.insert(0, id_models().into());
}
let mut tp = Type::from(tp);
let mut tp = Type::Path(tp);
for _ in 0..self.vec_count {
tp = generic_type(tp_vec(), tp);
}
if self.force_value {
tp = Type::from(tp_json_value())
tp = Type::Path(tp_json_value())
}
if self.is_reference() {
let tr = TypeReference {
attrs: Vec::new(),
and_token: Default::default(),
lifetime: Default::default(),
mutability: Default::default(),
elem: Box::new(tp),
};
tp = Type::from(tr);
tp = Type::Reference(tr);
}
if self.boxed {
tp = generic_type(tp_box(), tp);
Expand All @@ -327,13 +328,15 @@ impl TypeNameCode {
let bound = TraitBound {
path: path.path,
paren_token: None,
modifier: TraitBoundModifier::None,
modifiers: TraitBoundModifiers::default(),
maybe: None,
lifetimes: None,
};
let bound = TypeParamBound::Trait(bound);
let mut bounds = Punctuated::new();
bounds.push(bound);
tp = Type::ImplTrait(TypeImplTrait {
attrs: Vec::new(),
bounds,
impl_token: Impl::default(),
});
Expand Down Expand Up @@ -378,7 +381,7 @@ fn generic_type(mut wrap_tp: TypePath, tp: Type) -> Type {
if let Some(v) = wrap_tp.path.segments.last_mut() {
v.arguments = arguments
}
Type::from(wrap_tp)
Type::Path(wrap_tp)
}

impl From<TypePath> for TypeNameCode {
Expand Down Expand Up @@ -434,7 +437,11 @@ fn segments_to_type_path(segments: Vec<PathSegment>) -> TypePath {
segments: punctuated,
leading_colon: None,
};
TypePath { path, qself: None }
TypePath {
attrs: Vec::new(),
path,
qself: None,
}
}

fn idents_to_type_path(idents: Vec<Ident>) -> TypePath {
Expand Down
Loading