1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Contains the FileEntry struct that represents a file entry in a
//! hierarchical list.

use std::cell::RefCell;
use std::rc::Rc;
use super::composite_filedirentry_trait::{FileDirTypes, FileDirEntry};

//-----------------------------------------------------------------------------

/// Represents the file entry allowed in the hierarchy for the Composite design
/// pattern example.
pub struct FileEntry {
    /// Name of the file
    name: String,
    /// Timestamp of the file (expressed as a string)
    timestamp: String,
    /// Length of the file
    length: i32,
    /// Type of the entry as a value from the FileDirTypes enumeration.
    entry_type: FileDirTypes,
}


impl FileEntry {
    /// Constructor for FileEntry
    ///
    /// # Parameters
    /// - name
    ///
    ///   Name of the file.
    /// - length
    ///
    ///   Length of the file.
    /// - timestamp
    ///
    ///   String containing the timestamp for the file.
    ///
    /// # Returns
    /// Returns the new FileEntry object.
    pub fn new(name: &str, length: i32, timestamp: &str) -> FileEntry {
        FileEntry {
            name: name.to_string(),
            length: length,
            timestamp: timestamp.to_string(),
            entry_type: FileDirTypes::FileType,
        }
    }
}

impl FileDirEntry for FileEntry {
    fn entry_type(&self) -> &FileDirTypes {
        &self.entry_type
    }

    fn name(&self) -> &str {
        &self.name
    }
    
    fn timestamp(&self) -> &str {
        &self.timestamp
    }
    
    fn length(&mut self) -> i32 {
        self.length
    }
    
    fn children(&self) -> Option<&Vec<Rc<RefCell<dyn FileDirEntry>>>> {
        None
    }
}