Documentation fixes

This commit is contained in:
Wojciech Kozlowski 2023-03-29 15:31:42 +09:00
parent cadc799495
commit 96f824863c
3 changed files with 11 additions and 7 deletions

View File

@ -5,21 +5,23 @@ use std::path::Path;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;
use crate::database::DatabaseRead; use crate::database::{DatabaseRead, DatabaseWrite};
use super::DatabaseWrite;
/// A JSON file database.
pub struct DatabaseJson { pub struct DatabaseJson {
database_file: File, database_file: File,
} }
impl DatabaseJson { impl DatabaseJson {
/// Create a read-only database instance. If the JSON file does not exist, an error is returned.
pub fn reader(path: &Path) -> Result<Self, std::io::Error> { pub fn reader(path: &Path) -> Result<Self, std::io::Error> {
Ok(Self { Ok(Self {
database_file: File::open(path)?, database_file: File::open(path)?,
}) })
} }
/// Create a write-only database instance. If the file does not exist, it is created, if it does
/// exist, it is truncated.
pub fn writer(path: &Path) -> Result<Self, std::io::Error> { pub fn writer(path: &Path) -> Result<Self, std::io::Error> {
Ok(Self { Ok(Self {
database_file: File::create(path)?, database_file: File::create(path)?,

View File

@ -1,15 +1,17 @@
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde::Serialize; use serde::Serialize;
mod json; pub mod json;
trait DatabaseRead { /// Trait for database reads.
pub trait DatabaseRead {
fn read<D>(&mut self, collection: &mut D) -> Result<(), std::io::Error> fn read<D>(&mut self, collection: &mut D) -> Result<(), std::io::Error>
where where
D: DeserializeOwned; D: DeserializeOwned;
} }
trait DatabaseWrite { /// Trait for database writes.
pub trait DatabaseWrite {
fn write<S>(&mut self, collection: &S) -> Result<(), std::io::Error> fn write<S>(&mut self, collection: &S) -> Result<(), std::io::Error>
where where
S: Serialize; S: Serialize;

View File

@ -3,7 +3,7 @@
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
mod database; pub mod database;
/// [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier) (MBID). /// [MusicBrainz Identifier](https://musicbrainz.org/doc/MusicBrainz_Identifier) (MBID).
pub type Mbid = Uuid; pub type Mbid = Uuid;