forked from Cutieguwu/raven
Add documentation.
This commit is contained in:
@@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Error, Result};
|
||||
|
||||
/// Data struct
|
||||
/// [`Class`] represents a source file. It is a handler.
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Class {
|
||||
/// Path relative to PACKAGE/java, without file extension.
|
||||
@@ -14,6 +14,13 @@ pub struct Class {
|
||||
}
|
||||
|
||||
impl Class {
|
||||
/// Creates a new [`Class`].
|
||||
///
|
||||
/// # Error
|
||||
///
|
||||
/// * [`Error::MismatchedPackage`] if the provided `file_path` is absolute, and cannot be
|
||||
/// subtracted to just its relative path within its parent package.
|
||||
/// * [`Error::Io`] if the source file cannot be loaded and digested.
|
||||
pub fn new<P: AsRef<Path>>(package_src_root: P, file_path: P) -> Result<Self> {
|
||||
let mut file_path = file_path.as_ref().to_path_buf();
|
||||
if file_path.is_absolute() {
|
||||
@@ -27,6 +34,17 @@ impl Class {
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns a boolean representing if the class is up to date.
|
||||
///
|
||||
/// # Criteria
|
||||
///
|
||||
/// * The class path is local.
|
||||
/// * The class has been compiled to `target/`
|
||||
/// * The class' source file has not been updated.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * [`Error::Io`]
|
||||
pub fn is_updated<P: AsRef<Path>>(&self, class_path: P) -> Result<bool> {
|
||||
// If the path is local and that file has not been updated.
|
||||
Ok(class_path
|
||||
@@ -37,6 +55,13 @@ impl Class {
|
||||
&& self.checksum == sha256::try_digest(self.path.clone())?)
|
||||
}
|
||||
|
||||
/// Updates the class' checksum.
|
||||
///
|
||||
/// Only call this if you know that the class has been compiled successfully.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// * [`Error::Io`] if the source file cannot be loaded and digested.
|
||||
pub fn update<P: AsRef<Path>>(&mut self, package_src_root: P) -> Result<()> {
|
||||
self.checksum = sha256::try_digest(dbg!(
|
||||
package_src_root
|
||||
|
||||
Reference in New Issue
Block a user