Skip to content

Commit

Permalink
Fix return type to be ()
Browse files Browse the repository at this point in the history
  • Loading branch information
cgettys-microsoft committed Dec 20, 2024
1 parent ffd2a14 commit 1594d49
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crates/libs/core/src/runtime/activation_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl CodePackageActivationContext {
handler: T,
) -> crate::Result<ConfigurationPackageChangeCallbackHandle>
where
T: Fn(&ConfigurationPackageChangeEvent) -> crate::Result<()> + 'static,
T: Fn(&ConfigurationPackageChangeEvent) + 'static,
{
let lambda_handler = LambdaConfigurationPackageEventHandler::new(handler);
let bridge = ConfigurationPackageChangeEventHandlerBridge::new(lambda_handler);
Expand Down
17 changes: 8 additions & 9 deletions crates/libs/core/src/runtime/package_change/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use super::ConfigurationPackageChangeEvent;
/// Rust trait to turn rust code into IFabricConfigurationPackageChangeHandler.
/// Not exposed to user
pub trait ConfigurationPackageChangeEventHandler: 'static {
fn on_change(&self, change: &ConfigurationPackageChangeEvent) -> crate::Result<()>;
fn on_change(&self, change: &ConfigurationPackageChangeEvent);
}

// Bridge implementation for the change handler to turn rust code into SF com object.
Expand Down Expand Up @@ -49,8 +49,7 @@ where
) {
let new_package = ConfigurationPackage::from_com(configpackage.unwrap().clone());
let event = ConfigurationPackageChangeEvent::Addition { new_package };
// TODO: unwrap, or should we change the return type of the lambda to be the empty type?
self.inner.on_change(&event).unwrap();
self.inner.on_change(&event)
}

fn OnPackageRemoved(
Expand All @@ -60,7 +59,7 @@ where
) {
let previous_package = ConfigurationPackage::from_com(configpackage.unwrap().clone());
let event = ConfigurationPackageChangeEvent::Removal { previous_package };
self.inner.on_change(&event).unwrap();
self.inner.on_change(&event)
}

fn OnPackageModified(
Expand All @@ -76,7 +75,7 @@ where
previous_package,
new_package,
};
self.inner.on_change(&event).unwrap();
self.inner.on_change(&event)
}
}

Expand All @@ -86,14 +85,14 @@ where
/// Strictly speaking we don't need this layer. But it would allow us to open the door to trait implementations someday
pub(crate) struct LambdaConfigurationPackageEventHandler<T>
where
T: Fn(&ConfigurationPackageChangeEvent) -> crate::Result<()> + 'static,
T: Fn(&ConfigurationPackageChangeEvent),
{
f: T,
}

impl<T> LambdaConfigurationPackageEventHandler<T>
where
T: Fn(&ConfigurationPackageChangeEvent) -> crate::Result<()> + 'static,
T: Fn(&ConfigurationPackageChangeEvent) + 'static,
{
pub fn new(f: T) -> Self {
Self { f }
Expand All @@ -102,9 +101,9 @@ where

impl<T> ConfigurationPackageChangeEventHandler for LambdaConfigurationPackageEventHandler<T>
where
T: Fn(&ConfigurationPackageChangeEvent) -> crate::Result<()> + 'static,
T: Fn(&ConfigurationPackageChangeEvent) + 'static,
{
fn on_change(&self, change: &ConfigurationPackageChangeEvent) -> crate::Result<()> {
fn on_change(&self, change: &ConfigurationPackageChangeEvent) {
(self.f)(change)
}
}
Expand Down
2 changes: 0 additions & 2 deletions crates/samples/echomain/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ fn validate_configs(actctx: &CodePackageActivationContext) {
// or something more complicated, like a ArcSwap<Config> or similar
build_config(some_package.clone());
}

Ok(())
}).unwrap();
}

Expand Down
1 change: 0 additions & 1 deletion crates/samples/no_default_features/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fn test_fn() {
let changed_package_name = some_package.get_description().name.to_string_lossy();
let changed_package_str = &changed_package_name;
println!("Received config package change of type {change_type:?} to package {changed_package_str}");
Ok(())
}
).unwrap();
}

0 comments on commit 1594d49

Please sign in to comment.