TextureSync/server/texture-sync-server/src/model/mod.rs

50 lines
1.0 KiB
Rust
Raw Normal View History

use serde::Serialize;
2019-05-03 11:19:34 +02:00
use std::io;
mod sha256;
pub use sha256::Sha256;
2019-04-20 01:24:19 +02:00
mod date;
pub use date::Date;
mod texture_format;
pub use texture_format::TextureFormat;
2019-05-05 19:16:52 +02:00
#[derive(Eq, PartialEq, Clone, Serialize, Deserialize, Debug, Hash)]
2019-04-20 01:24:19 +02:00
pub struct Texture {
pub id: String,
pub name: String,
pub tags: Vec<String>,
pub format: TextureFormat,
pub added_on: Date,
pub resolution: (u64, u64),
2019-04-20 01:24:19 +02:00
pub texture_hash: Sha256,
}
2019-05-03 11:19:34 +02:00
pub enum ReplaceTextureStatus {
/// Done.
2019-05-03 11:19:34 +02:00
Ok,
/// Call Again With Texture Binary
2019-05-03 11:19:34 +02:00
NeedTextureData(Sha256),
}
pub type ProtocolResult<T> = Result<T, ProtocolError>;
pub enum ProtocolError {
BadRequest(String),
FileNotFound(String),
Conflict(String),
InternalServerError(std::io::Error),
NotImplemented,
}
2019-05-03 11:19:34 +02:00
impl From<io::Error> for ProtocolError {
fn from(err: io::Error) -> Self {
2019-05-05 20:28:35 +02:00
if err.kind() == io::ErrorKind::NotFound {
ProtocolError::FileNotFound("File Not Found!".to_string())
} else {
ProtocolError::InternalServerError(err)
}
}
2019-05-03 11:19:34 +02:00
}