Skip to content

Commit

Permalink
chore: apply some lints and fixes (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre authored Jun 26, 2024
1 parent 1fe170d commit c1b1012
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 1 addition & 2 deletions unleash-yggdrasil/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,7 @@ impl EngineState {
}
let total_weight: u32 = variants.iter().map(|var| var.weight as u32).sum();

let stickiness = variants
.get(0)
let stickiness = variants.first()
.and_then(|variant| variant.stickiness.clone());

let target = get_seed(stickiness, context)
Expand Down
2 changes: 1 addition & 1 deletion unleash-yggdrasil/src/strategy_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ mod tests {
expected_value: bool,
) {
let constraint_ips = constraint_ips
.split(",")
.split(',')
.map(|x| format!("\"{}\"", x.trim()))
.collect::<Vec<String>>();

Expand Down
5 changes: 4 additions & 1 deletion unleash-yggdrasil/src/strategy_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ enum StrategyType {
FlexibleRollout,
RemoteAddress,
ApplicationHostname,
//This is a catch all handler on the enum type because we don't know what the
// custom strategy will be called ahead of time
#[allow(dead_code)]
Custom(String),
}

Expand All @@ -31,7 +34,7 @@ impl IsCustom for Strategy {
}
}

pub fn upgrade(strategies: &Vec<Strategy>, segment_map: &HashMap<i32, Segment>) -> String {
pub fn upgrade(strategies: &[Strategy], segment_map: &HashMap<i32, Segment>) -> String {
if strategies.is_empty() {
return "true".into();
}
Expand Down
6 changes: 3 additions & 3 deletions yggdrasilffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<T> From<Result<Option<T>, FFIError>> for Response<T> {
enum FFIError {
Utf8Error,
InvalidJson,
NullError(String),
NullError,
}

const KNOWN_STRATEGIES: [&str; 8] = [
Expand Down Expand Up @@ -79,15 +79,15 @@ impl From<serde_json::Error> for FFIError {

unsafe fn get_engine<'a>(engine_ptr: *mut c_void) -> Result<&'a mut EngineState, FFIError> {
if engine_ptr.is_null() {
Err(FFIError::NullError("Null engine pointer".into()))
Err(FFIError::NullError)
} else {
Ok(unsafe { &mut *(engine_ptr as *mut EngineState) })
}
}

unsafe fn get_str<'a>(ptr: *const c_char) -> Result<&'a str, FFIError> {
if ptr.is_null() {
Err(FFIError::NullError("Null pointer".into()))
Err(FFIError::NullError)
} else {
unsafe { CStr::from_ptr(ptr).to_str().map_err(FFIError::from) }
}
Expand Down

0 comments on commit c1b1012

Please sign in to comment.