Skip to content

Commit 74864ff

Browse files
committed
align_of -> align_to
1 parent f47f0d8 commit 74864ff

File tree

5 files changed

+47
-53
lines changed

5 files changed

+47
-53
lines changed

epserde-derive/src/lib.rs

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,11 @@ fn gen_type_info_where_clauses(
429429
bound_align_hash.push(syn::parse_quote!(::epserde::traits::AlignHash));
430430
let align_hash = gen_type_info_where_clause(bound_align_hash);
431431

432-
let mut bound_align_of = Punctuated::new();
433-
bound_align_of.push(syn::parse_quote!(::epserde::traits::AlignTo));
434-
let align_of = gen_type_info_where_clause(bound_align_of);
432+
let mut bound_align_to = Punctuated::new();
433+
bound_align_to.push(syn::parse_quote!(::epserde::traits::AlignTo));
434+
let align_to = gen_type_info_where_clause(bound_align_to);
435435

436-
(type_hash, align_hash, align_of)
436+
(type_hash, align_hash, align_to)
437437
}
438438

439439
/// Context structure for the [`Epserde`] derive macro.
@@ -591,9 +591,7 @@ fn gen_epserde_struct_impl(ctx: &EpserdeContext, s: &syn::DataStruct) -> proc_ma
591591
use ::epserde::deser::DeserInner;
592592

593593
Ok(#name{
594-
#(
595-
#field_names: unsafe { <#field_types as DeserInner>::_deser_full_inner(backend)? },
596-
)*
594+
#( #field_names: unsafe { <#field_types as DeserInner>::_deser_full_inner(backend)? }, )*
597595
})
598596
}
599597

@@ -606,9 +604,7 @@ fn gen_epserde_struct_impl(ctx: &EpserdeContext, s: &syn::DataStruct) -> proc_ma
606604
use ::epserde::deser::DeserInner;
607605

608606
Ok(#name{
609-
#(
610-
#method_calls,
611-
)*
607+
#( #method_calls, )*
612608
})
613609
}
614610
}
@@ -1114,19 +1110,18 @@ fn gen_enum_align_hash_body(
11141110
}
11151111

11161112
/// Generates the `AlignTo` implementation body for struct types.
1117-
fn gen_struct_align_of_body(fields_types: &[&syn::Type]) -> proc_macro2::TokenStream {
1113+
fn gen_struct_align_to_body(fields_types: &[&syn::Type]) -> proc_macro2::TokenStream {
11181114
quote! {
11191115
use ::epserde::traits::AlignTo;
1120-
use ::epserde::ser::SerType;
11211116

1122-
let mut align_of = ::core::mem::align_of::<Self>();
1117+
let mut align_to = ::core::mem::align_of::<Self>();
11231118

11241119
#(
1125-
if align_of < <#fields_types as AlignTo>::align_to() {
1126-
align_of = <#fields_types as AlignTo>::align_to();
1120+
if align_to < <#fields_types as AlignTo>::align_to() {
1121+
align_to = <#fields_types as AlignTo>::align_to();
11271122
}
11281123
)*
1129-
align_of
1124+
align_to
11301125
}
11311126
}
11321127

@@ -1136,21 +1131,21 @@ fn gen_type_info_traits(
11361131
ctx: TypeInfoContext,
11371132
type_hash_where_clause: syn::WhereClause,
11381133
align_hash_where_clause: syn::WhereClause,
1139-
align_of_where_clause: syn::WhereClause,
1134+
align_to_where_clause: syn::WhereClause,
11401135
type_hash_body: proc_macro2::TokenStream,
11411136
align_hash_body: proc_macro2::TokenStream,
1142-
align_of_body: Option<proc_macro2::TokenStream>,
1137+
align_to_body: Option<proc_macro2::TokenStream>,
11431138
) -> proc_macro2::TokenStream {
11441139
let name = &ctx.name;
11451140
let generics_for_impl = &ctx.generics_for_impl;
11461141
let generics_for_type = &ctx.generics_for_type;
11471142

1148-
let align_of_impl = if let Some(align_of_body) = align_of_body {
1143+
let align_to_impl = if let Some(align_to_body) = align_to_body {
11491144
quote! {
11501145
#[automatically_derived]
1151-
impl #generics_for_impl ::epserde::traits::AlignTo for #name #generics_for_type #align_of_where_clause {
1146+
impl #generics_for_impl ::epserde::traits::AlignTo for #name #generics_for_type #align_to_where_clause {
11521147
fn align_to() -> usize {
1153-
#align_of_body
1148+
#align_to_body
11541149
}
11551150
}
11561151
}
@@ -1168,7 +1163,6 @@ fn gen_type_info_traits(
11681163

11691164
#[automatically_derived]
11701165
impl #generics_for_impl ::epserde::traits::AlignHash for #name #generics_for_type #align_hash_where_clause {
1171-
11721166
fn align_hash(
11731167
hasher: &mut impl ::core::hash::Hasher,
11741168
offset_of: &mut usize,
@@ -1177,7 +1171,7 @@ fn gen_type_info_traits(
11771171
}
11781172
}
11791173

1180-
#align_of_impl
1174+
#align_to_impl
11811175
}
11821176
}
11831177

@@ -1199,7 +1193,7 @@ fn gen_struct_type_info_impl(
11991193
field_types_ts.push(quote! { SerType<#field_type> });
12001194
}
12011195

1202-
let (type_hash_where_clause, align_hash_where_clause, align_of_where_clause) =
1196+
let (type_hash_where_clause, align_hash_where_clause, align_to_where_clause) =
12031197
gen_type_info_where_clauses(ctx.where_clause, ctx.is_zero_copy, &field_types);
12041198

12051199
// Generate field hashes for TypeHash
@@ -1215,8 +1209,8 @@ fn gen_struct_type_info_impl(
12151209
// Generate implementation bodies
12161210
let type_hash_body = gen_type_hash_body(&ctx, &field_hashes);
12171211
let align_hash_body = gen_struct_align_hash_body(&ctx, &field_types_ts);
1218-
let align_of_body = if ctx.is_zero_copy {
1219-
Some(gen_struct_align_of_body(&field_types))
1212+
let align_to_body = if ctx.is_zero_copy {
1213+
Some(gen_struct_align_to_body(&field_types))
12201214
} else {
12211215
None
12221216
};
@@ -1225,18 +1219,18 @@ fn gen_struct_type_info_impl(
12251219
ctx,
12261220
type_hash_where_clause,
12271221
align_hash_where_clause,
1228-
align_of_where_clause,
1222+
align_to_where_clause,
12291223
type_hash_body,
12301224
align_hash_body,
1231-
align_of_body,
1225+
align_to_body,
12321226
)
12331227
}
12341228

12351229
/// [`TypeInfo`] derive code for enum types.
12361230
fn gen_enum_type_info_impl(ctx: TypeInfoContext, e: &syn::DataEnum) -> proc_macro2::TokenStream {
12371231
let mut all_type_hashes = vec![];
12381232
let mut all_align_hashes = vec![];
1239-
let mut all_align_ofs = vec![];
1233+
let mut all_align_tos = vec![];
12401234
let mut all_field_types = vec![];
12411235
let mut all_repl_params = HashSet::new();
12421236

@@ -1246,7 +1240,7 @@ fn gen_enum_type_info_impl(ctx: TypeInfoContext, e: &syn::DataEnum) -> proc_macr
12461240
let mut type_hash = quote! { Hash::hash(stringify!(#ident), hasher); };
12471241
let mut field_types = vec![];
12481242
let mut align_hash = quote! {};
1249-
let mut align_of = quote! {};
1243+
let mut align_to = quote! {};
12501244

12511245
match &variant.fields {
12521246
syn::Fields::Unit => {}
@@ -1268,9 +1262,9 @@ fn gen_enum_type_info_impl(ctx: TypeInfoContext, e: &syn::DataEnum) -> proc_macr
12681262
<#field_type_ts as AlignHash>::align_hash(hasher, offset_of);
12691263
}]);
12701264

1271-
align_of.extend([quote! {
1272-
if align_of < <#field_type as AlignTo>::align_to() {
1273-
align_of = <#field_type as AlignTo>::align_to();
1265+
align_to.extend([quote! {
1266+
if align_to < <#field_type as AlignTo>::align_to() {
1267+
align_to = <#field_type as AlignTo>::align_to();
12741268
}
12751269
}]);
12761270

@@ -1302,9 +1296,9 @@ fn gen_enum_type_info_impl(ctx: TypeInfoContext, e: &syn::DataEnum) -> proc_macr
13021296
<#field_type_ts as AlignHash>::align_hash(hasher, offset_of);
13031297
}]);
13041298

1305-
align_of.extend([quote! {
1306-
if align_of < <#field_type as AlignTo>::align_to() {
1307-
align_of = <#field_type as AlignTo>::align_to();
1299+
align_to.extend([quote! {
1300+
if align_to < <#field_type as AlignTo>::align_to() {
1301+
align_to = <#field_type as AlignTo>::align_to();
13081302
}
13091303
}]);
13101304

@@ -1322,25 +1316,25 @@ fn gen_enum_type_info_impl(ctx: TypeInfoContext, e: &syn::DataEnum) -> proc_macr
13221316

13231317
all_type_hashes.push(type_hash);
13241318
all_align_hashes.push(align_hash);
1325-
all_align_ofs.push(align_of);
1319+
all_align_tos.push(align_to);
13261320
all_field_types.extend(field_types);
13271321
}
13281322

1329-
let (where_clause_type_hash, where_clause_align_hash, where_clause_align_of) =
1323+
let (where_clause_type_hash, where_clause_align_hash, where_clause_align_to) =
13301324
gen_type_info_where_clauses(ctx.where_clause, ctx.is_zero_copy, &all_field_types);
13311325

13321326
let type_hash_body = gen_type_hash_body(&ctx, &all_type_hashes);
13331327
let align_hash_body = gen_enum_align_hash_body(&ctx, &all_align_hashes);
1334-
let align_of_body = quote! {
1335-
let mut align_of = core::mem::align_of::<Self>();
1328+
let align_to_body = quote! {
1329+
let mut align_to = core::mem::align_of::<Self>();
13361330
#(
1337-
#all_align_ofs
1331+
#all_align_tos
13381332
)*
1339-
align_of
1333+
align_to
13401334
};
13411335

1342-
let align_of_body = if ctx.is_zero_copy {
1343-
Some(align_of_body)
1336+
let align_to_body = if ctx.is_zero_copy {
1337+
Some(align_to_body)
13441338
} else {
13451339
None
13461340
};
@@ -1349,10 +1343,10 @@ fn gen_enum_type_info_impl(ctx: TypeInfoContext, e: &syn::DataEnum) -> proc_macr
13491343
ctx,
13501344
where_clause_type_hash,
13511345
where_clause_align_hash,
1352-
where_clause_align_of,
1346+
where_clause_align_to,
13531347
type_hash_body,
13541348
align_hash_body,
1355-
align_of_body,
1349+
align_to_body,
13561350
)
13571351
}
13581352

epserde/examples/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
let full = unsafe { <[usize; 100]>::deserialize_full(&mut cursor).unwrap() };
2222
println!(
2323
"Full-copy deserialization type: {}",
24-
core::any::type_name_of_val(&full)
24+
core::any::type_name::<[usize; 100]>(),
2525
);
2626
println!("Value: {:x?}", full);
2727

epserde/src/impls/tuple.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ macro_rules! impl_tuples {
6666
impl<T: AlignTo> AlignTo for ($($t,)*)
6767
{
6868
fn align_to() -> usize {
69-
let mut align_of = 0;
70-
$(if align_of < core::cmp::max(align_of, <$t>::align_to()) {
71-
align_of = <$t>::align_to();
69+
let mut align_to = 0;
70+
$(if align_to < core::cmp::max(align_to, <$t>::align_to()) {
71+
align_to = <$t>::align_to();
7272
})*
73-
align_of
73+
align_to
7474
}
7575
}
7676

epserde/src/ser/write_with_names.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use alloc::{
3636
/// which uses the default implementation, and [`SchemaWriter`], which
3737
/// additionally records a [`Schema`] of the serialized data.
3838
pub trait WriteWithNames: WriteWithPos + Sized {
39-
/// Add some zero padding so that `self.pos() % V:align_of() == 0.`
39+
/// Add some zero padding so that `self.pos() % V:align_to() == 0.`
4040
///
4141
/// Other implementations must write the same number of zeros.
4242
fn align<V: AlignTo>(&mut self) -> Result<()> {

epserde/tests/test_max_size_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct MyStruct {
3232

3333
#[test]
3434
/// Check that we don't have any collision on most types
35-
fn test_align_of_align() {
35+
fn test_align_to() {
3636
assert_eq!(64, MyStruct64::align_to());
3737
assert_eq!(MyStruct::align_to(), MyStruct2::align_to());
3838

0 commit comments

Comments
 (0)