protospec_build/prelude/
pad.rs1use super::*;
2
3pub struct PadFunction;
4
5impl ForeignFunction for PadFunction {
6 fn arguments(&self) -> Vec<FFIArgument> {
7 vec![
8 FFIArgument {
9 name: "pad".to_string(),
10 type_: Some(Type::Scalar(ScalarType::U64)),
11 optional: false,
12 },
13 FFIArgument {
14 name: "base".to_string(),
15 type_: Some(Type::Scalar(ScalarType::U64)),
16 optional: false,
17 }
18 ]
19 }
20
21 fn return_type(&self) -> Type {
22 Type::Scalar(ScalarType::U64)
23 }
24
25 fn call(&self, arguments: &[FFIArgumentValue]) -> TokenStream {
26 let pad = &arguments[0].value;
27 let base = &arguments[1].value;
28 return quote! {
29 if #base % #pad == 0 {
30 #base
31 } else {
32 #base + (#pad - (#base % #pad))
33 }
34 };
35 }
36}