// main author: Robin Willmann // date : see git. // WIP, changes welcome mod model { pub struct Sha256(pub [64;u8]); pub struct Texture { pub id : String, pub name : String, pub tags : Vec, pub format : TextureFormat, pub resolution : (usize, usize), pub texture_hash : Sha256 } pub enum TextureFormat { PNG, JPG } } mod protocol { use crate::model::*; pub enum ReplaceTextureStatus { // Call Again With Texture Binary NeedTextureData, // Done. Ok, } pub type ProtocolResult = Result; pub enum ProtocolError { BadRequest(pub String), FileNotFound(pub String), Conflict(pub String), InternalServerError(pub std::io::Error), NotImplemented, } pub trait ProtocolHandler : Send + Sync { fn query(mut self, &[String]) -> ProtocolError>; fn get_texture_by_id(mut self, id : String) -> ProtocolError>; fn get_texture_by_name(mut self, id : String) -> ProtocolError>; fn get_texture_file(mut self, hash : Sha256) -> ProtocolError>; fn get_texture_preview(mut self, hash : Sha256) -> ProtocolError>; fn replace_texture(mut self, delete : Option, insert : Option, insert_texture_data : Option> ) -> ProtocolError; } pub struct ProtocolConfig { pub port : u16, } pub fn listen_forever(handler : &ProtocolHandler) -> { unimplemend!() } } mod persistency { use std::io; pub struct DataStore { // private attributes } impl DataStore { pub fn new(path : Path) -> io::Result { unimplemend!() } pub fn garbage_collect() -> io::Result<()> { unimplemend!() } // TODO: think } mod search { use crate::model::*; pub struct Query { filters : Vec, } pub type QueryParserResult = Result; pub enum QuerySyntaxError { UnknownFilter, } impl Query { pub fn parse(input : &[String]) -> QueryParserResult{ unimplemend!() } } pub fn search(input : &[Texture], query : &Query) -> Vec { } //private enum QueryFilterModifier{ None(QueryFilter), Not(QueryFilter), } //private enum QueryFilter { TagName(String), InName(String), MinResolution(usize), BeforeDate { year : u16, month : u16, day : u16, } } } } mod image_convert { use crate::model::*; pub struct ConvertConfig { pub desired_size : (usize, usize), } pub generate_preview( input : Vec, format : Format config : ConvertConfig, ) -> ::image::ImageResult>; } mod main { struct ServerState { // private attributes } impl ProtocolHandler for ServerState { // .... } pub fn main(){ unimplemend!() } }