Skip to content

Instantly share code, notes, and snippets.

@greyltc
Created April 19, 2024 02:44
Show Gist options
  • Save greyltc/1d0d8cbe14113a721b7df8168eb25ece to your computer and use it in GitHub Desktop.
Save greyltc/1d0d8cbe14113a721b7df8168eb25ece to your computer and use it in GitHub Desktop.
rust question
/// function 1: fine
pub async fn spawn(self, addr: SocketAddr) -> Result<impl Server, Box<dyn std::error::Error>> {
let storage = Disk::new(self.path).map_err(Error::from).await?;
let storage = Verify::new(storage);
log::info!("Local disk storage initialized.");
Ok(spawn_server(storage, &addr))
}
/// function 2: fine
pub async fn spawn(self, addr: SocketAddr) -> Result<impl Server, Box<dyn std::error::Error>> {
let storage = Disk::new(self.path).map_err(Error::from).await?;
let storage = Verify::new(Encrypted::new(self.key.unwrap(), storage));
log::info!("Local disk storage initialized.");
Ok(spawn_server(storage, &addr))
}
/// function 3: fail with "`if` and `else` have incompatible types"
pub async fn spawn(self, addr: SocketAddr) -> Result<impl Server, Box<dyn std::error::Error>> {
let storage = Disk::new(self.path).map_err(Error::from).await?;
let storage =
if self.key.is_some() {
Verify::new(Encrypted::new(self.key.unwrap(), storage))
} else {
Verify::new(storage)
};
log::info!("Local disk storage initialized.");
Ok(spawn_server(storage, &addr))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment