Created
March 24, 2021 17:11
-
-
Save mkmik/90035ad8413ca5ed9d878d6eae5873c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
use ::rpc::field_mask::{FieldMaskExt, RequiredFieldMaskExt}; | |
use generated_types::google::{protobuf::FieldMask, FieldViolation}; | |
fn find(v: &[String], s: &str) -> bool { | |
v.iter().any(|i| i.split('.').next().unwrap() == s) | |
} | |
fn is_wildcard(mask: &FieldMask) -> bool { | |
mask.paths.is_empty() | |
} | |
let mask = mask.clone().required()?; | |
{ | |
if is_wildcard(&mask) || find(&mask.paths, stringify!( id )) { | |
match cfg.id { | |
id => { | |
match mask.new_inner(stringify!( id )) { | |
#[allow(unused_variables)] | |
mask => ({ process_id(id)? }) | |
} | |
} | |
#[allow(unreachable_patterns)] | |
_ => return Err(FieldViolation::required(stringify!( id ).to_string()).into()), | |
}; | |
} | |
}; | |
{ | |
if is_wildcard(&mask) || find(&mask.paths, stringify!( something )) { | |
match cfg.something { | |
Some(ref something) => { | |
match mask.new_inner(stringify!( something )) { | |
#[allow(unused_variables)] | |
mask => (process_something(something, mask)?) | |
} | |
} | |
#[allow(unreachable_patterns)] | |
_ => return Err(FieldViolation::required(stringify!( something ).to_string()).into()), | |
}; | |
} | |
}; | |
{ | |
if is_wildcard(&mask) || find(&mask.paths, stringify!( other )) { | |
match cfg.other { | |
Some(ref other) => { | |
match mask.new_inner(stringify!( other )) { | |
#[allow(unused_variables)] | |
mask => { | |
::std::io::_print(IntellijRustDollarCrate::format_args_nl!( "{}" , 1 + other . bar )); | |
} | |
} | |
} | |
#[allow(unreachable_patterns)] | |
_ => return Err(FieldViolation::required(stringify!( other ).to_string()).into()), | |
}; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment