tag.rs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // imag - the personal information management suite for the commandline
  3. // Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
  4. //
  5. // This library is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU Lesser General Public
  7. // License as published by the Free Software Foundation; version
  8. // 2.1 of the License.
  9. //
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. // Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public
  16. // License along with this library; if not, write to the Free Software
  17. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. //
  19. use std::path::PathBuf;
  20. use libimagstore::store::Result as StoreResult;
  21. use libimagstore::storeid::IntoStoreId;
  22. use libimagstore::storeid::StoreId;
  23. /// A tag for time-tracking. This is not a normal `libimagentrytag` tag, because we want the user
  24. /// give the possibility to use the tagging functionality without interfering with this functionality.
  25. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
  26. pub struct TimeTrackingTag(String);
  27. impl TimeTrackingTag {
  28. pub fn as_str(&self) -> &str {
  29. &self.0
  30. }
  31. }
  32. impl Into<String> for TimeTrackingTag {
  33. fn into(self) -> String {
  34. self.0
  35. }
  36. }
  37. impl From<String> for TimeTrackingTag {
  38. fn from(s: String) -> TimeTrackingTag {
  39. TimeTrackingTag(s)
  40. }
  41. }
  42. impl<'a> From<&'a String> for TimeTrackingTag {
  43. fn from(s: &'a String) -> TimeTrackingTag {
  44. TimeTrackingTag(s.clone())
  45. }
  46. }
  47. impl IntoStoreId for TimeTrackingTag {
  48. fn into_storeid(self) -> StoreResult<StoreId> {
  49. StoreId::new_baseless(PathBuf::from(self.0))
  50. }
  51. }