diff --git a/lib_rs/control.rs b/lib_rs/control.rs index 7f031cc4d4e5cd81bb5ff7d6fc2889e83bf6ad14..82bdd04cf37568b1d6d81f2f81b67990d757a912 100644 --- a/lib_rs/control.rs +++ b/lib_rs/control.rs @@ -126,19 +126,19 @@ impl ControlError { pub fn as_handler_error<E>(error: E) -> Self where E: std::error::Error { - return Self::HandlerError(error.to_string()); + Self::HandlerError(error.to_string()) } } impl From<std::io::Error> for ControlError { fn from(err: std::io::Error) -> Self { - return Self::IOError(err.to_string()); + Self::IOError(err.to_string()) } } impl From<toml::ser::Error> for ControlError { fn from(err: toml::ser::Error) -> Self { - return Self::TOMLError(err.to_string()); + Self::TOMLError(err.to_string()) } } @@ -226,12 +226,12 @@ impl<'a, T, U> ScanOp<'a, T, U> { let params: ParamsList = params.into_iter().collect(); let N: usize = params.values().map(|v| v.len()).product(); let Z: usize = ((N as f64).log10() + 1.0) as usize; - return Self { + Self { params, action: Box::new(action), N, Z, - }; + } } /// Create an iterator over the Cartesian product of `self`'s parameters @@ -250,7 +250,7 @@ impl<'a, T, U> ScanOp<'a, T, U> { .collect(); op_params }); - return ScanOpIter { iter: Box::new(iter) } + ScanOpIter { iter: Box::new(iter) } } } @@ -278,7 +278,7 @@ struct OpIdx<'a> { impl<'a> OpIdx<'a> { fn new(name: &'a str, cur: usize, size: usize, width: usize) -> Self { - return Self { name, cur, size, width }; + Self { name, cur, size, width } } } @@ -377,7 +377,7 @@ impl<'a> OpIdx<'a> { /// let b0: f64 = params["b0"]; /// let b1: f64 = params["b1"]; /// target.push((b0, b1)); -/// return Ok(()); +/// Ok(()) /// } /// ``` pub struct Scanner<'a, F, T, U> @@ -394,7 +394,7 @@ for Scanner<'a, F, T, U> where F: Fn(&mut T) -> ControlResult<U> { fn as_ref(&self) -> &IndexMap<String, ScanOp<'a, T, U>> { - return &self.ops; + &self.ops } } @@ -403,7 +403,7 @@ for Scanner<'a, F, T, U> where F: Fn(&mut T) -> ControlResult<U> { fn as_mut(&mut self) -> &mut IndexMap<String, ScanOp<'a, T, U>> { - return &mut self.ops; + &mut self.ops } } @@ -459,7 +459,7 @@ where F: Fn(&mut T) -> ControlResult<U> .rev() .chain([1]) .collect(); - return Self { ops, main_action, total_shots, subtotals }; + Self { ops, main_action, total_shots, subtotals } } /// Computes output progress strings during execution. @@ -486,7 +486,7 @@ where F: Fn(&mut T) -> ControlResult<U> ) }) .fold(String::new(), |acc, it| acc + &it); - return format!("\r {}({:6.2}%)", idx_str, progress_percent); + format!("\r {}({:6.2}%)", idx_str, progress_percent) } /// Worker function for [`Self::execute`]. This function is the one that @@ -523,7 +523,7 @@ where F: Fn(&mut T) -> ControlResult<U> print_flush!("{}", self.outstr(idx, false)); outs.push((self.main_action)(target)?); } - return Ok(()); + Ok(()) } /// Recursively execute all [`ScanOp`]s, returning all their outputs in a @@ -557,7 +557,7 @@ where F: Fn(&mut T) -> ControlResult<U> total_time / self.total_shots as f64, ); } - return Ok(outs); + Ok(outs) } } @@ -616,7 +616,7 @@ impl<'a, S> SequenceBuilder<'a, S> { where B: SequenceBlock<State = S> + 'a { self.blocks.insert(name.to_string(), (Box::new(block), color)); - return self; + self } /// Process all recorded blocks in the order they were added and assemble @@ -642,7 +642,7 @@ impl<'a, S> SequenceBuilder<'a, S> { .with_color(*color); super_seq.insert(name.to_string(), seq); } - return Ok((super_seq, state)); + Ok((super_seq, state)) } } @@ -666,7 +666,7 @@ impl<'a, S> SequenceBuilder<'a, S> { /// println!("Encountered error {}; running handler", err); /// return controller.on_error(err); /// } -/// return controller.postcmd(); +/// controller.postcmd() /// } /// ``` /// Note that errors occurring before [`Self::execute`] is called are returned @@ -715,7 +715,7 @@ pub trait Controller: Sized { println!("\nEncountered error: {}; running handler", err); return controller.on_error(err); } - return controller.postcmd(); + controller.postcmd() } } @@ -1026,10 +1026,10 @@ impl Serialize for Value { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer { - return match self { + match self { Self::Static(val) => val.serialize(serializer), Self::Scanned(vals) => vals.serialize(serializer), - }; + } } } @@ -1039,10 +1039,10 @@ macro_rules! impl_try_from_value_static { type Error = ControlError; fn try_from(v: Value) -> ControlResult<Self> { - return match v { + match v { Value::Static(v) => v.try_into(), _ => Err(ControlError::ValueNotStatic), - }; + } } } } @@ -1055,10 +1055,10 @@ impl TryFrom<Value> for Vec<f64> { type Error = ControlError; fn try_from(v: Value) -> ControlResult<Self> { - return match v { + match v { Value::Scanned(v) => Ok(v), _ => Err(ControlError::ValueNotScanned), - }; + } } } @@ -1087,10 +1087,10 @@ impl TryFrom<StaticValue> for usize { type Error = ControlError; fn try_from(v: StaticValue) -> ControlResult<Self> { - return match v { + match v { StaticValue::USize(u) => Ok(u), _ => Err(ControlError::StaticValueNotUSize), - }; + } } } @@ -1098,10 +1098,10 @@ impl TryFrom<StaticValue> for u32 { type Error = ControlError; fn try_from(v: StaticValue) -> ControlResult<Self> { - return match v { + match v { StaticValue::U32(u) => Ok(u), _ => Err(ControlError::StaticValueNotU32), - }; + } } } @@ -1109,10 +1109,10 @@ impl TryFrom<StaticValue> for f64 { type Error = ControlError; fn try_from(v: StaticValue) -> ControlResult<Self> { - return match v { + match v { StaticValue::F64(f) => Ok(f), _ => Err(ControlError::StaticValueNotF64), - }; + } } } @@ -1120,11 +1120,11 @@ impl Serialize for StaticValue { fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer { - return match self { + match self { Self::USize(u) => u.serialize(serializer), Self::U32(u) => u.serialize(serializer), Self::F64(f) => f.serialize(serializer), - }; + } } } diff --git a/lib_rs/dataio.rs b/lib_rs/dataio.rs index f222e8120550c4c307ebc5ff8c90609cce2920e5..e591384e17990b49547515aaf76d0c92a845855e 100644 --- a/lib_rs/dataio.rs +++ b/lib_rs/dataio.rs @@ -26,10 +26,10 @@ pub fn get_timestr(with_sep: bool) -> String { "[hour][minute][second]" } ).unwrap(); - return time::OffsetDateTime::now_local() + time::OffsetDateTime::now_local() .unwrap() .format(&fmt) - .unwrap(); + .unwrap() } /// Get today's date as a `String` in the `year`-`month`-`day` format. @@ -43,10 +43,10 @@ pub fn get_datestr(with_sep: bool) -> String { "[year][month][day]" } ).unwrap(); - return time::OffsetDateTime::now_local() + time::OffsetDateTime::now_local() .unwrap() .format(&fmt) - .unwrap(); + .unwrap() } /// Get the current date and time as a `String` in the @@ -62,10 +62,10 @@ pub fn get_timedatestr(with_sep: bool) -> String { "[year][month][day][hour][minute][second]" } ).unwrap(); - return time::OffsetDateTime::now_local() + time::OffsetDateTime::now_local() .unwrap() .format(&fmt) - .unwrap(); + .unwrap() } /// A collection of named [`PathBuf`]s. @@ -84,12 +84,12 @@ impl DataPaths { I: IntoIterator<Item = (String, P)>, P: AsRef<Path>, { - return paths.into_iter().collect(); + paths.into_iter().collect() } /// Get a path under the given key if it exists and clone it out of storage. pub fn get_cloned(&self, key: &str) -> Option<PathBuf> { - return self.paths.get(key).cloned(); + self.paths.get(key).cloned() } /// Insert a new path into `self`. @@ -106,7 +106,7 @@ where P: AsRef<Path> fn from_iter<I>(iter: I) -> Self where I: IntoIterator<Item = (String, P)> { - return Self { + Self { paths: iter.into_iter() .map(|(label, path)| (label, path.as_ref().to_path_buf())) .collect() @@ -130,7 +130,7 @@ impl IntoIterator for DataPaths { type IntoIter = DataPathsIntoIter; fn into_iter(self) -> Self::IntoIter { - return DataPathsIntoIter { iter: self.paths.into_iter() }; + DataPathsIntoIter { iter: self.paths.into_iter() } } } @@ -156,7 +156,7 @@ impl Index<&str> for DataPaths { type Output = PathBuf; fn index(&self, index: &str) -> &Self::Output { - return self.get(index).unwrap(); + self.get(index).unwrap() } } diff --git a/lib_rs/lib.rs b/lib_rs/lib.rs index 64d00b26d4bc8a365acb2485e67836cd8df19308..69f7b2dd9870d9d6d7c480960dda7137935a258d 100644 --- a/lib_rs/lib.rs +++ b/lib_rs/lib.rs @@ -1,5 +1,4 @@ #![allow(dead_code, non_snake_case, non_upper_case_globals)] -#![allow(clippy::needless_return)] pub use ew_control; pub use moglabs_control; diff --git a/lib_rs/rtcontrol/maps.rs b/lib_rs/rtcontrol/maps.rs index 7aafd24d59aab3045294609c6459e50e167de122..cdc731bc2e6c053f8cf4b43d0cb3331e4bdbbd90 100644 --- a/lib_rs/rtcontrol/maps.rs +++ b/lib_rs/rtcontrol/maps.rs @@ -43,16 +43,16 @@ pub static MAP_REGISTRY: phf::Map<&'static str, MapFn> }; fn check_nargs(args: &[String], n: usize, source_fn: &str) -> RTResult<()> { - return (args.len() == n).then_some(()) + (args.len() == n).then_some(()) .ok_or(RTError::MappingFunctionError(format!( "{}: expected exactly {} argument(s)", source_fn, n, - ))); + ))) } fn parse_onoff(s: &str, source_fn: &str) -> RTResult<bool> { - return match s { + match s { "on" => Ok(true), "off" => Ok(false), x => { @@ -69,16 +69,16 @@ fn parse_onoff(s: &str, source_fn: &str) -> RTResult<bool> { ))) } }, - }; + } } fn parse_float(s: &str, source_fn: &str) -> RTResult<f64> { - return s.parse() + s.parse() .map_err(|_| RTError::MappingFunctionError(format!( "{}: expected a number, but got {}", source_fn, s - ))); + ))) } fn get_connection( @@ -87,12 +87,12 @@ fn get_connection( source_fn: &str, ) -> RTResult<Connection> { - return connections.get(key).copied() + connections.get(key).copied() .ok_or(RTError::MappingFunctionError(format!( "{}: missing connection '{}'", source_fn, key - ))); + ))) } pub fn mot3_green_onoff(connections: &ConnectionLayout, args: &[String]) @@ -105,10 +105,10 @@ pub fn mot3_green_onoff(connections: &ConnectionLayout, args: &[String]) = get_connection(connections, "mot3_green_aom", FN_NAME)?; let sh: Connection = get_connection(connections, "mot3_green_sh", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom, (!onoff).for_conn(&aom)), (sh, onoff.for_conn(&sh)), - ]); + ]) } pub fn mot3_green_aom_amfm(connections: &ConnectionLayout, args: &[String]) @@ -122,10 +122,10 @@ pub fn mot3_green_aom_amfm(connections: &ConnectionLayout, args: &[String]) = get_connection(connections, "mot3_green_aom_am", FN_NAME)?; let aom_fm: Connection = get_connection(connections, "mot3_green_aom_fm", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_am, system::mot3_green_aom_am(am)?.for_conn(&aom_am)), (aom_fm, system::mot3_green_aom_fm(fm)?.for_conn(&aom_fm)), - ]); + ]) } pub fn mot3_green_aom_am(connections: &ConnectionLayout, args: &[String]) @@ -136,9 +136,9 @@ pub fn mot3_green_aom_am(connections: &ConnectionLayout, args: &[String]) let am: f64 = parse_float(&args[0], FN_NAME)?; let aom_am: Connection = get_connection(connections, "mot3_green_aom_am", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_am, system::mot3_green_aom_am(am)?.for_conn(&aom_am)), - ]); + ]) } pub fn mot3_green_aom_fm(connections: &ConnectionLayout, args: &[String]) @@ -149,9 +149,9 @@ pub fn mot3_green_aom_fm(connections: &ConnectionLayout, args: &[String]) let fm: f64 = parse_float(&args[0], FN_NAME)?; let aom_fm: Connection = get_connection(connections, "mot3_green_aom_fm", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_fm, system::mot3_green_aom_fm(fm)?.for_conn(&aom_fm)), - ]); + ]) } pub fn probe_green_onoff(connections: &ConnectionLayout, args: &[String]) @@ -164,10 +164,10 @@ pub fn probe_green_onoff(connections: &ConnectionLayout, args: &[String]) = get_connection(connections, "probe_green_aom", FN_NAME)?; let sh: Connection = get_connection(connections, "probe_green_sh_2", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom, (!onoff).for_conn(&aom)), (sh, onoff.for_conn(&sh)), - ]); + ]) } pub fn probe_green_aom_am(connections: &ConnectionLayout, args: &[String]) @@ -178,9 +178,9 @@ pub fn probe_green_aom_am(connections: &ConnectionLayout, args: &[String]) let am: f64 = parse_float(&args[0], FN_NAME)?; let aom_am: Connection = get_connection(connections, "probe_green_aom_am", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_am, system::probe_green_aom_am(am).for_conn(&aom_am)), - ]); + ]) } pub fn qinit_green_onoff(connections: &ConnectionLayout, args: &[String]) @@ -195,11 +195,11 @@ pub fn qinit_green_onoff(connections: &ConnectionLayout, args: &[String]) = get_connection(connections, "qinit_green_aom", FN_NAME)?; let sh: Connection = get_connection(connections, "qinit_green_sh", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_0, onoff.for_conn(&aom_0)), (aom, (!onoff).for_conn(&aom)), (sh, onoff.for_conn(&sh)), - ]); + ]) } pub fn qinit_green_aom_amfm(connections: &ConnectionLayout, args: &[String]) @@ -213,10 +213,10 @@ pub fn qinit_green_aom_amfm(connections: &ConnectionLayout, args: &[String]) = get_connection(connections, "qinit_green_aom_am", FN_NAME)?; let aom_fm: Connection = get_connection(connections, "qinit_green_aom_fm", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_am, am.for_conn(&aom_am)), (aom_fm, system::qinit_green_aom_fm(fm)?.for_conn(&aom_fm)), - ]); + ]) } pub fn qinit_green_aom_am(connections: &ConnectionLayout, args: &[String]) @@ -227,9 +227,9 @@ pub fn qinit_green_aom_am(connections: &ConnectionLayout, args: &[String]) let am: f64 = parse_float(&args[0], FN_NAME)?; let aom_am: Connection = get_connection(connections, "qinit_green_aom_am", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_am, am.for_conn(&aom_am)), - ]); + ]) } pub fn qinit_green_aom_fm(connections: &ConnectionLayout, args: &[String]) @@ -240,9 +240,9 @@ pub fn qinit_green_aom_fm(connections: &ConnectionLayout, args: &[String]) let fm: f64 = parse_float(&args[0], FN_NAME)?; let aom_fm: Connection = get_connection(connections, "qinit_green_aom_fm", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom_fm, system::qinit_green_aom_fm(fm)?.for_conn(&aom_fm)), - ]); + ]) } pub fn tweezer_aod_am(connections: &ConnectionLayout, args: &[String]) @@ -253,9 +253,9 @@ pub fn tweezer_aod_am(connections: &ConnectionLayout, args: &[String]) let am: f64 = parse_float(&args[0], FN_NAME)?; let aod_am: Connection = get_connection(connections, "tweezer_aod_am", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aod_am, system::tweezer_aod_am(am, false)?.for_conn(&aod_am)), - ]); + ]) } pub fn clock_onoff(connections: &ConnectionLayout, args: &[String]) @@ -266,7 +266,7 @@ pub fn clock_onoff(connections: &ConnectionLayout, args: &[String]) let onoff: bool = parse_onoff(&args[0], FN_NAME)?; let aom: Connection = get_connection(connections, "clock_aom", FN_NAME)?; - return Ok(vec![ + Ok(vec![ (aom, onoff.for_conn(&aom)), - ]); + ]) } diff --git a/lib_rs/rtcontrol/parser.rs b/lib_rs/rtcontrol/parser.rs index 70a335ca2bb1909d214547c585d076e723fef35e..5751a29e135968d67f6abb5d69da422fe8beee01 100644 --- a/lib_rs/rtcontrol/parser.rs +++ b/lib_rs/rtcontrol/parser.rs @@ -124,7 +124,7 @@ impl RTParser { } }, } - return Ok(()); + Ok(()) } } @@ -136,7 +136,7 @@ pub fn parse_set(input: &[String], connections: &ConnectionLayout) = Regex::new(r"^([a-zA-Z0-9_:+\-]+)=([+\-]?(\d*\.)?\d+)$").unwrap(); let digital_addr_pat = Regex::new(r"^(\d):(\d{1,2})$").unwrap(); let analog_addr_pat = Regex::new(r"^(\d{1,2})$").unwrap(); - return input.iter() + input.iter() .map(|arg| { if let Some(keyval) = keyval_pat.captures(arg) { if let Some(d_addr) @@ -169,7 +169,7 @@ pub fn parse_set(input: &[String], connections: &ConnectionLayout) Err(RTError::ParseArgKeyValue(arg.to_string())) } }) - .collect(); + .collect() } /// Parse input for [`Command::Mapset`]. @@ -199,7 +199,7 @@ pub fn parse_mapset( } }) .collect::<RTResult<Vec<Vec<(Connection, Voltage)>>>>()?; - return Ok(parsed.into_iter().flatten().collect()); + Ok(parsed.into_iter().flatten().collect()) } diff --git a/lib_rs/system.rs b/lib_rs/system.rs index 1174b6b79cebd66cd5a0f5c7f222b1247943f379..2f6ebf5167837edca682a8c0892e8f50e36fac46 100644 --- a/lib_rs/system.rs +++ b/lib_rs/system.rs @@ -54,17 +54,17 @@ macro_rules! sysdef_connections { impl SystemDefault<Connections> for Connections { fn sysdef() -> Connections { - return Connections { + Connections { $( $name: $connection, )* - }; + } } } impl Connections { pub fn as_layout() -> ConnectionLayout { - return connection_layout!( + connection_layout!( $( stringify!($name) => $connection, )* - ); + ) } } } @@ -142,7 +142,7 @@ sysdef_connections!{ pub struct DataHome; impl SystemDefault<PathBuf> for DataHome { fn sysdef() -> PathBuf { - return PathBuf::from(r"C:\Users\EW\Documents\Data"); + PathBuf::from(r"C:\Users\EW\Documents\Data") } } @@ -157,18 +157,18 @@ macro_rules! sysdef_datadirs { impl SystemDefault<DataDirs> for DataDirs { fn sysdef() -> DataDirs { let home: PathBuf = DataHome::sysdef(); - return DataDirs { + DataDirs { $( $name: home.join($path), )* - }; + } } } impl DataDirs { pub fn as_datapaths() -> DataPaths { let home: PathBuf = DataHome::sysdef(); - return datapaths!( + datapaths!( $( stringify!($name) => home.join($path), )* - ); + ) } } } @@ -195,12 +195,12 @@ sysdef_datadirs! { pub struct Main; impl SystemDefault<EWResult<Computer>> for Main { fn sysdef() -> EWResult<Computer> { - return Computer::connect( + Computer::connect( ([128, 174, 248, 206], 50100), Some(1), Some(1.0), Connections::as_layout(), - ); + ) } } @@ -216,10 +216,10 @@ pub const MOGRF_COM: u8 = 5; pub struct MOGRF; impl SystemDefault<MOGResult<MOGDriver>> for MOGRF { fn sysdef() -> MOGResult<MOGDriver> { - return MOGDriver::connect( + MOGDriver::connect( format!("COM{}", MOGRF_COM), MOGSerialSettings::default(), - ); + ) } } @@ -230,10 +230,10 @@ pub const DIM3000_COM: u8 = 4; pub struct TimeBase; impl SystemDefault<TBResult<DIM3000>> for TimeBase { fn sysdef() -> TBResult<DIM3000> { - return DIM3000::connect( + DIM3000::connect( format!("COM{}", DIM3000_COM), TBSerialSettings::default(), - ); + ) } } @@ -244,10 +244,10 @@ pub const DIM3000_QINIT_COM: u8 = 3; pub struct TimeBaseQinit; impl SystemDefault<TBResult<DIM3000>> for TimeBaseQinit { fn sysdef() -> TBResult<DIM3000> { - return DIM3000::connect( + DIM3000::connect( format!("COM{}", DIM3000_QINIT_COM), TBSerialSettings::default(), - ); + ) } } @@ -258,7 +258,7 @@ pub const RIGOL_ADDR: &str = "USB0::0x1AB1::0x0641::DG4E222600824::INSTR"; pub struct Rigol; impl SystemDefault<RigolResult<DG4000>> for Rigol { fn sysdef() -> RigolResult<DG4000> { - return DG4000::connect(RIGOL_ADDR, Some(1.0)); + DG4000::connect(RIGOL_ADDR, Some(1.0)) } } @@ -270,7 +270,7 @@ pub const RIGOL_MAG_ADDR: &str = "USB0::0x1AB1::0x0643::DG8A233304068::INSTR"; pub struct RigolMag; impl SystemDefault<RigolResult<DG800>> for RigolMag { fn sysdef() -> RigolResult<DG800> { - return DG800::connect(RIGOL_MAG_ADDR, Some(1.0)); + DG800::connect(RIGOL_MAG_ADDR, Some(1.0)) } } @@ -294,62 +294,62 @@ pub const SHIM_COILS_UD_ZERO: f64 = -0.308; // V // G -> V pub fn shim_coils_fb_mag(fb: f64) -> f64 { - return fb / (0.4 * 1.45) + SHIM_COILS_FB_ZERO; + fb / (0.4 * 1.45) + SHIM_COILS_FB_ZERO } // V -> G pub fn shim_coils_fb_mag_inv(fb: f64) -> f64 { - return (fb - SHIM_COILS_FB_ZERO) * 0.4 * 1.45; + (fb - SHIM_COILS_FB_ZERO) * 0.4 * 1.45 } // G -> Vpp pub fn shim_coils_fb_mag_amp(fb: f64) -> f64 { - return (shim_coils_fb_mag(fb.abs()) - SHIM_COILS_FB_ZERO) * 2.0; + (shim_coils_fb_mag(fb.abs()) - SHIM_COILS_FB_ZERO) * 2.0 } // G -> V pub fn shim_coils_lr_mag(lr: f64) -> f64 { - return lr / (0.4 * 1.92) + SHIM_COILS_LR_ZERO; + lr / (0.4 * 1.92) + SHIM_COILS_LR_ZERO } // V -> G pub fn shim_coils_lr_mag_inv(lr: f64) -> f64 { - return (lr - SHIM_COILS_LR_ZERO) * 0.4 * 1.92; + (lr - SHIM_COILS_LR_ZERO) * 0.4 * 1.92 } // G -> Vpp pub fn shim_coils_lr_mag_amp(lr: f64) -> f64 { - return (shim_coils_lr_mag(lr.abs()) - SHIM_COILS_LR_ZERO) * 2.0; + (shim_coils_lr_mag(lr.abs()) - SHIM_COILS_LR_ZERO) * 2.0 } // G -> V pub fn shim_coils_ud_mag(ud: f64) -> f64 { - return ud / (0.4 * 4.92) + SHIM_COILS_UD_ZERO; + ud / (0.4 * 4.92) + SHIM_COILS_UD_ZERO } // V -> G pub fn shim_coils_ud_mag_inv(ud: f64) -> f64 { - return (ud - SHIM_COILS_UD_ZERO) * 0.4 * 4.92; + (ud - SHIM_COILS_UD_ZERO) * 0.4 * 4.92 } // G -> Vpp pub fn shim_coils_ud_mag_amp(ud: f64) -> f64 { - return (shim_coils_ud_mag(ud.abs()) - SHIM_COILS_UD_ZERO) * 2.0; + (shim_coils_ud_mag(ud.abs()) - SHIM_COILS_UD_ZERO) * 2.0 } // G -> DAC pub fn hholtz_conv(hholtz: f64) -> u32 { - return (hholtz / 2.9499 / 271.6e-6).round() as u32; + (hholtz / 2.9499 / 271.6e-6).round() as u32 } // G -> DAC pub fn hholtz_conv_msg(hholtz: f64) -> (u32, u8) { - return (hholtz_conv(hholtz), AD5791_MSG_LEN); + (hholtz_conv(hholtz), AD5791_MSG_LEN) } // DAC -> G pub fn hholtz_conv_inv(hholtz: u32) -> f64 { - return hholtz as f64 * 2.9499 * 271.6e-6; + hholtz as f64 * 2.9499 * 271.6e-6 } pub const MOT3_GREEN_TB_FM_CENTER: f64 = 92.0; @@ -368,11 +368,11 @@ fn mot3_green_aom_fm_10(f: f64) -> SystemResult<f64> { let f0: f64 = MOT3_GREEN_TB_FM_CENTER; (-3.1_f64..=3.2).contains(&(f - f0)).then_some(()) .ok_or(SystemError::ValueOutOfRange("mot3_green_aom_fm_10", f))?; - return Ok( + Ok( A.into_iter().enumerate() .map(|(k, ak)| ak * (f - f0).powi(k as i32)) .sum() - ); + ) } // MOT3_GREEN_TB_FM_CENTER center; depth = 6.5536 MHz (n = 11) @@ -389,15 +389,15 @@ fn mot3_green_aom_fm_11(f: f64) -> SystemResult<f64> { let f0: f64 = MOT3_GREEN_TB_FM_CENTER; (-3.1_f64..=3.2).contains(&(f - f0)).then_some(()) .ok_or(SystemError::ValueOutOfRange("mot3_green_aom_fm_11", f))?; - return Ok( + Ok( A.into_iter().enumerate() .map(|(k, ak)| ak * (f - f0).powi(k as i32)) .sum() - ); + ) } pub fn mot3_green_aom_fm(f: f64) -> SystemResult<f64> { - return mot3_green_aom_fm_10(f); + mot3_green_aom_fm_10(f) } // 29.0 nominal; -60 ADC offset @@ -408,7 +408,7 @@ pub fn mot3_green_aom_am(p: f64) -> SystemResult<f64> { (-25.0..=29.5).contains(&p).then_some(()) .ok_or(SystemError::ValueOutOfRange("mot3_green_aom_am", p))?; - return Ok(A / (p - P0).powi(2) + B); + Ok(A / (p - P0).powi(2) + B) } pub fn mot3_green_alt_am(s: f64, f: f64) -> SystemResult<f64> { @@ -428,7 +428,7 @@ pub fn mot3_green_alt_am(s: f64, f: f64) -> SystemResult<f64> { let v: f64 = (-B + (B.powi(2) - 4.0 * A * (C - sp / sf0)).sqrt()) / (2.0 * A); (0.0..f64::INFINITY).contains(&v).then_some(()) .ok_or(SystemError::ValueOutOfRange("mot3_green_alt_am", s))?; - return Ok(v); + Ok(v) } pub const PROBE_GREEN_TB_FM_CENTER: f64 = 94.0; @@ -448,11 +448,11 @@ fn probe_green_aom_fm_10(f: f64) -> SystemResult<f64> { let f0: f64 = PROBE_GREEN_TB_FM_CENTER; (-3.05..=3.15).contains(&(f - f0)).then_some(()) .ok_or(SystemError::ValueOutOfRange("probe_green_aom_fm_10", f))?; - return Ok( + Ok( A.into_iter().enumerate() .map(|(k, ak)| ak * (f - f0).powi(k as i32)) .sum() - ); + ) } // PROBE_GREEN_TB_FM_CENTER center; depth = 6.5536 MHz (n = 11) @@ -470,11 +470,11 @@ fn probe_green_aom_fm_11(f: f64) -> SystemResult<f64> { let f0: f64 = PROBE_GREEN_TB_FM_CENTER; (-6.1..=6.3).contains(&(f - f0)).then_some(()) .ok_or(SystemError::ValueOutOfRange("probe_green_aom_fm_11", f))?; - return Ok( + Ok( A.into_iter().enumerate() .map(|(k, ak)| ak * (f - f0).powi(k as i32)) .sum() - ); + ) } // NOTE: ACTUAL FREQUENCIES ARE SHIFTED BY -200 kHz AT THIS SETTING @@ -492,11 +492,11 @@ fn probe_green_aom_fm_12(f: f64) -> SystemResult<f64> { let f0: f64 = PROBE_GREEN_TB_FM_CENTER; (-12.1..=13.0).contains(&(f - f0)).then_some(()) .ok_or(SystemError::ValueOutOfRange("probe_green_aom_fm_12", f))?; - return Ok( + Ok( A.into_iter().enumerate() .map(|(k, ak)| ak * (f - f0).powi(k as i32)) .sum() - ); + ) } pub fn probe_green_aom_fm(f: f64, warn_only: bool) -> SystemResult<f64> { @@ -514,7 +514,7 @@ pub fn probe_green_aom_fm(f: f64, warn_only: bool) -> SystemResult<f64> { let a: f64 = 0.75820; let b: f64 = -0.08133; let v: f64 = (fp - b) / a; - return Ok(v); + Ok(v) } pub fn probe_green_double_f(f: f64, warn_only: bool) -> SystemResult<f64> { @@ -530,7 +530,7 @@ pub fn probe_green_double_f(f: f64, warn_only: bool) -> SystemResult<f64> { return Err(SystemError::ValueOutOfRange("probe_green_double_f", f)); } } - return Ok(f_aom); + Ok(f_aom) } pub fn probe_green_aom_am(s: f64) -> f64 { @@ -553,7 +553,7 @@ pub fn probe_green_aom_am(s: f64) -> f64 { // let v: f64 = 0.01545167 * sp + 0.11277884; // measured on 01.10.2023 let v: f64 = 0.01337659 * sp + 0.10192844; - return v; + v } pub const QINIT_GREEN_TB_FM_CENTER: f64 = 80.0; @@ -573,7 +573,7 @@ pub fn qinit_green_aom_fm(f: f64) -> SystemResult<f64> { (fp.abs() <= 6.0).then_some(()) .ok_or(SystemError::ValueOutOfRange("qinit_green_aom_fm", f))?; let v: f64 = (fp - B) / A; - return Ok(v); + Ok(v) } pub const CLOCK_TB_FM_CENTER: f64 = 90.0; @@ -598,11 +598,11 @@ pub fn clock_aom_fm(f: f64, warn_only: bool) -> SystemResult<f64> { return Err(SystemError::ValueOutOfRange("clock_aom_fm", f)); } } - return Ok( + Ok( A.into_iter().enumerate() .map(|(k, ak)| ak * (f - f0).powi(k as i32)) .sum() - ); + ) } // 5 tweezers, scale = 2^12 @@ -629,7 +629,7 @@ fn tweezer_aod_am_array5(U: f64, warn_only: bool) -> SystemResult<f64> { return Err(SystemError::ValueOutOfRange("tweezer_aod_am_array5", U)); } } - return Ok(v); + Ok(v) } fn tweezer_aod_am_array15(U: f64, warn_only: bool) -> SystemResult<f64> { @@ -644,7 +644,7 @@ fn tweezer_aod_am_array15(U: f64, warn_only: bool) -> SystemResult<f64> { return Err(SystemError::ValueOutOfRange("tweezer_aod_am_array15", U)); } } - return Ok(v); + Ok(v) } fn tweezer_aod_am_array10(U: f64, warn_only: bool) -> SystemResult<f64> { @@ -659,7 +659,7 @@ fn tweezer_aod_am_array10(U: f64, warn_only: bool) -> SystemResult<f64> { return Err(SystemError::ValueOutOfRange("tweezer_aod_am_array10", U)); } } - return Ok(v); + Ok(v) } fn tweezer_aod_am_array20(U: f64, warn_only: bool) -> SystemResult<f64> { @@ -701,9 +701,9 @@ fn tweezer_aod_am_array20(U: f64, warn_only: bool) -> SystemResult<f64> { return Err(SystemError::ValueOutOfRange("tweezer_aod_am_array20", U)); } } - return Ok(v); + Ok(v) } pub fn tweezer_aod_am(U: f64, warn_only: bool) -> SystemResult<f64> { - return tweezer_aod_am_array20(U, warn_only); + tweezer_aod_am_array20(U, warn_only) } diff --git a/lib_rs/utils.rs b/lib_rs/utils.rs index dd2f62880fe9ec4a10dca1b6abe78396d586408a..66c63bc6e0eb07f38b687978796982a7bef01e2c 100644 --- a/lib_rs/utils.rs +++ b/lib_rs/utils.rs @@ -41,7 +41,7 @@ pub fn logspace(base: f64, beg_exp: f64, end_exp: f64, points: usize) /// Print any printable value and return it. pub fn qq<T: std::fmt::Debug>(val: T) -> T { println!("{:?}", val); - return val; + val } /// Simple trait to find maxima and minima of `f64` collections using @@ -58,26 +58,26 @@ pub trait FExtrema { impl FExtrema for Vec<f64> { fn fmax(&self) -> Option<f64> { - return self.iter() + self.iter() .copied() - .max_by(|l, r| l.total_cmp(r)); + .max_by(|l, r| l.total_cmp(r)) } fn fmax_idx(&self) -> Option<(usize, f64)> { - return self.iter() + self.iter() .copied() .enumerate() .max_by(|l, r| l.1.total_cmp(&r.1)) } fn fmin(&self) -> Option<f64> { - return self.iter() + self.iter() .copied() - .min_by(|l, r| l.total_cmp(r)); + .min_by(|l, r| l.total_cmp(r)) } fn fmin_idx(&self) -> Option<(usize, f64)> { - return self.iter() + self.iter() .copied() .enumerate() .min_by(|l, r| l.1.total_cmp(&r.1)) @@ -91,7 +91,7 @@ pub trait Average { impl Average for Vec<f64> { fn avg(&self) -> f64 { - return self.iter().copied().sum::<f64>() / self.len() as f64; + self.iter().copied().sum::<f64>() / self.len() as f64 } }