places/storage/bookmarks/
conversions.rs1use super::{
6 BookmarkPosition, BookmarkUpdateInfo, InvalidPlaceInfo, UpdatableBookmark, UpdatableFolder,
7 UpdatableItem, UpdatableSeparator, UpdateTreeLocation,
8};
9
10use crate::error::Result;
11use crate::types::BookmarkType;
12use sync_guid::Guid as SyncGuid;
13use url::Url;
14
15impl BookmarkUpdateInfo {
16 pub fn into_updatable(self, ty: BookmarkType) -> Result<(SyncGuid, UpdatableItem)> {
19 if self.title.is_some() && ty == BookmarkType::Separator {
22 return Err(InvalidPlaceInfo::IllegalChange("title", ty).into());
23 }
24
25 if self.url.is_some() && ty != BookmarkType::Bookmark {
26 return Err(InvalidPlaceInfo::IllegalChange("url", ty).into());
27 }
28
29 let location = match (self.parent_guid, self.position) {
30 (None, None) => UpdateTreeLocation::None,
31 (None, Some(pos)) => UpdateTreeLocation::Position {
32 pos: BookmarkPosition::Specific { pos },
33 },
34 (Some(parent_guid), pos) => UpdateTreeLocation::Parent {
35 guid: parent_guid,
36 pos: pos.map_or(BookmarkPosition::Append, |p| BookmarkPosition::Specific {
37 pos: p,
38 }),
39 },
40 };
41
42 let updatable = match ty {
43 BookmarkType::Bookmark => UpdatableItem::Bookmark {
44 b: UpdatableBookmark {
45 location,
46 title: self.title,
47 url: self.url.map(|u| Url::parse(&u)).transpose()?,
48 },
49 },
50 BookmarkType::Separator => UpdatableItem::Separator {
51 s: UpdatableSeparator { location },
52 },
53 BookmarkType::Folder => UpdatableItem::Folder {
54 f: UpdatableFolder {
55 location,
56 title: self.title,
57 },
58 },
59 };
60
61 Ok((self.guid, updatable))
62 }
63}