forked from rust-postgres/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomposites.rs
More file actions
28 lines (24 loc) · 701 Bytes
/
Copy pathcomposites.rs
File metadata and controls
28 lines (24 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use syn::{Error, Ident, Type};
use crate::overrides::Overrides;
pub struct Field {
pub name: String,
pub ident: Ident,
pub type_: Type,
}
impl Field {
pub fn parse(raw: &syn::Field) -> Result<Field, Error> {
let overrides = Overrides::extract(&raw.attrs)?;
let ident = raw.ident.as_ref().unwrap().clone();
Ok(Field {
name: overrides.name.unwrap_or_else(|| {
let name = ident.to_string();
match name.strip_prefix("r#") {
Some(name) => name.to_string(),
None => name,
}
}),
ident,
type_: raw.ty.clone(),
})
}
}