Created
April 19, 2024 02:44
-
-
Save greyltc/1d0d8cbe14113a721b7df8168eb25ece to your computer and use it in GitHub Desktop.
rust question
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
/// 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