igor 0.1.2

Generic text-based vendoring
Documentation
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
use std::fmt;
use std::io::{BufRead, BufReader};
use std::path::Component;
use std::sync::Arc;
use ahash::AHashMap;
use anyhow::anyhow;
use async_stream::stream;
use log::{debug, trace, warn};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde::de::{MapAccess, Visitor};
use serde::ser::SerializeMap;
use stringreader::StringReader;
use tokio::sync::RwLock;
use tokio::sync::mpsc::{Receiver,channel};
use crate::config_model::WriteMode::{Ignore, Overwrite};
use crate::file_system::fixture::FixtureContent::{DirFixtureContent, FileFixtureContent};
use crate::path::AbsolutePath;
use super::*;

#[derive(Debug)]
enum FixtureContent {
    DirFixtureContent { entries: RwLock<AHashMap<OsString, Arc<FixtureEntry>>> },
    FileFixtureContent { lines: RwLock<Vec<String>>},
}

#[derive(Clone, Debug)]
struct FixtureFileSystem {
    data: Arc<FixtureEntry>,
}

#[derive(Debug)]
struct FixtureEntry {
    file_name: OsString,
    path: AbsolutePath,
    is_dir: bool,
    content: FixtureContent,
}

struct FixtureSourceFile {
    lines: Receiver<String>,
}

impl DirEntry for Arc<FixtureEntry> {
    fn path(&self) -> PathBuf {
        self.path.to_path_buf()
    }

    fn file_name(&self) -> OsString {
        self.file_name.clone()
    }

    async fn is_dir(&self) -> Result<bool> {
        Ok(self.is_dir)
    }
}

impl TargetFile for Arc<FixtureEntry> {
    async fn write_line<S: Into<String> + Debug + Send>(&self, line: S) -> Result<()> {
        if let FileFixtureContent { lines, .. } = &self.content {
            let mut lines = lines.write().await;
            lines.push(line.into());
            Ok(())
        } else {
            Err(anyhow!("Trying to write a line to a directory: {:?}: {:?}", &line, &self.path))
        }
    }

    async fn close(&mut self) -> Result<()> {
        Ok(())
    }
}

impl SourceFile for FixtureSourceFile {
    async fn next_line(&mut self) -> Result<Option<String>> {
        Ok(self.lines.recv().await)
    }
}

impl FileSystem for FixtureFileSystem {
    type DirEntryItem = Arc<FixtureEntry>;

    async fn read_dir(&self, directory: &AbsolutePath) -> Result<impl Stream<Item=Result<Self::DirEntryItem>> + Send + Sync + Unpin> {
        let entries = stream! {
            let dir_entry = self.find_entry(directory, |_,_| Ok(None)).await?;
            if let DirFixtureContent { entries, .. } = &dir_entry.content {
                let entries_content = entries.read().await;
                for (_entry_name, entry) in entries_content.iter() {
                    yield Ok(entry.clone());
                }
            }
        };
        Ok(Box::pin(entries))
    }

    async fn path_type(&self, path: &AbsolutePath) -> PathType {
        let Ok(entry) = self.find_entry(path, |_,_| Ok(None)).await else { return PathType::Missing };
        if entry.is_dir {
            PathType::Directory
        } else {
            PathType::File
        }
    }

    async fn open_target(&self, file_path: AbsolutePath, write_mode: WriteMode, executable: bool) -> Result<Option<impl TargetFile>> {
        if write_mode == Ignore {
            return Ok(None);
        }
        if executable {
            return Err(anyhow!("Fixture does not support executable target files: {file_path:?}"));
        }
        let current = self.find_parent_entry(&file_path).await?;
        if let Some(file_name_ref) = file_path.file_name() {
            let file_name = file_name_ref.to_os_string();
            match &current.content {
                DirFixtureContent { entries, .. } => {
                    let mut entries_content = entries.write().await;
                    if let Some(file_entry) = entries_content.get(&file_name.clone()) {
                        if write_mode == Overwrite {
                            if let FileFixtureContent { lines, .. } = &file_entry.content {
                                {
                                    let mut lines_content = lines.write().await;
                                    lines_content.truncate(0)
                                }
                                Ok(Some(file_entry.clone()))
                            } else {
                                Err(anyhow!("Trying to write lines to a directory: {:?}", file_path))
                            }
                        } else {
                            Ok(None)
                        }
                    } else {
                        let content = FileFixtureContent{
                            lines: RwLock::new(Vec::new()),
                        };
                        let new_dir_entry = Arc::new(FixtureEntry {
                            file_name: file_name.clone(),
                            path: file_path.clone(),
                            is_dir: false,
                            content
                        });
                        entries_content.insert(file_name, new_dir_entry.clone());
                        Ok(Some(new_dir_entry))
                    }
                },
                _ => Err(anyhow!("Not a directory: {:?}", file_path.parent()))
            }
        } else {
            Err(anyhow!("Missing file name: {:?}", file_path))
        }
    }

    async fn open_source(&self, file_path: AbsolutePath) -> Result<impl SourceFile> {
        debug!("Open source: {:?}", &file_path);
        let file_entry = self.find_entry(&file_path, |_,_| Ok(None)).await?;
        if file_entry.is_dir().await? {
            Err(anyhow!("Trying to read lines from a directory: {:?}", file_path))
        } else {
            let (tx, rx) = channel(10);
            tokio::spawn(send_lines(file_entry.clone(), tx));
            Ok(FixtureSourceFile { lines: rx })
        }
    }
}

async fn send_lines(file: Arc<FixtureEntry>, tx: Sender<String>) {
    if let FileFixtureContent {lines, ..} = &file.content {
        let lines_read = lines.read().await;
        for line in lines_read.iter() {
            if let Err(e) = tx.send(line.to_string()).await {
                warn!("Error sending line: {:?}", e);
                break;
            }
        }
    }
}

impl FixtureFileSystem {
    async fn find_parent_entry(&self, child_path: &AbsolutePath) -> Result<Arc<FixtureEntry>> {
        if let Some(dir_path) = child_path.parent() {
            let dir_path = AbsolutePath::try_new(dir_path.to_path_buf())?;
            debug!("Find entry for: {:?}", &dir_path);
            Ok(self.find_entry(&dir_path, create_new_directory).await?)
        } else {
            debug!("Found root: {:?}", &self.data.path);
            Ok(self.data.clone())
        }
    }

    async fn find_entry(&self, dir_path: &AbsolutePath, dir_creator: impl DirectoryCreator) -> Result<Arc<FixtureEntry>> {
        let mut current = self.data.clone();
        let mut current_path = PathBuf::from("/");

        let mut components = dir_path.components().peekable();
        if let Some(Component::RootDir) = &mut components.peek() {
            let _root_dir = components.next();
        }

        for component in components {
            if let Component::RootDir = component {
                continue;
            }
            debug!("Component: {:?}", &component);
            let child_entry;
            if let DirFixtureContent {entries,..} = &current.content {
                current_path.push(component);
                debug!("Searching entry in {:?}", &current_path);
                let part = component.as_os_str().to_os_string();
                let entry_option = {
                    let entries_content = entries.read().await;
                    entries_content.get(&part).map(Arc::clone)
                };
                if let Some(entry) = entry_option {
                    child_entry = entry.clone();
                } else {
                    if let Some(new_dir_entry) = dir_creator(&current_path, &part)? {
                        child_entry = Arc::new(new_dir_entry);
                        let mut entries_content = entries.write().await;
                        entries_content.insert(part, child_entry.clone());
                        debug!("Created new directory: {:?}", child_entry);
                    } else {
                        debug!("Not found: {:?}", &current_path);
                        return Err(anyhow!("Not found: {:?}", &current_path));
                    }
                }
            } else {
                return Err(anyhow!("Not a directory: {:?}", &current_path))
            }
            current = child_entry;
        }
        debug!("Found entry: {:?}", &current.path);
        Ok(current)
    }
}

trait DirectoryCreator: Fn(&PathBuf, &OsString) -> Result<Option<FixtureEntry>> {}

// Trick to be able to pass functions with a matching signature as
// implementations of DirectoryCreator
impl<F> DirectoryCreator for F
where F: Fn(&PathBuf, &OsString) -> Result<Option<FixtureEntry>>,
{}

fn create_new_directory(current_path: &PathBuf, part: &OsString) -> Result<Option<FixtureEntry>> {
    let new_dir = DirFixtureContent {
        entries: RwLock::new(AHashMap::new()),
    };
    let new_entry_path = AbsolutePath::try_new(current_path.clone())?;
    let new_dir_entry = FixtureEntry {
        file_name: part.clone(),
        path: new_entry_path,
        is_dir: true,
        content: new_dir
    };
    debug!("Created new directory: {:?}", new_dir_entry);
    Ok(Some(new_dir_entry))
}

#[derive(Deserialize,Serialize,Debug)]
#[serde(untagged)]
enum FixtureEnum {
    Dir(FixtureDirectory),
    File(String),
}

#[derive(Debug)] // Serialize and Deserialize implemented below
struct FixtureDirectory(AHashMap<String,Box<FixtureEnum>>);

struct FixtureDirectoryVisitor;

impl<'de> Visitor<'de> for FixtureDirectoryVisitor {
    type Value = FixtureDirectory;

    fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("a map of fixture enum entries")
    }

    fn visit_map<M>(self, mut access: M) -> std::result::Result<Self::Value, M::Error>
    where
        M: MapAccess<'de>,
    {
        let mut map = AHashMap::new();
        while let Some((key, value)) = access.next_entry()? {
            map.insert(key, value);
        }
        Ok(FixtureDirectory(map))
    }
}

impl<'de> Deserialize<'de> for FixtureDirectory {
    fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
    where
        D: Deserializer<'de>
    {
        deserializer.deserialize_map(FixtureDirectoryVisitor)
    }
}

impl From<FixtureEnum> for FixtureFileSystem {
    fn from(value: FixtureEnum) -> Self {
        let root = AbsolutePath::root();
        let root_entry = convert_enum(&root, &"/", Box::new(value));
        FixtureFileSystem { data: Arc::new(root_entry) }
    }
}

fn convert_enum(parent_path: &AbsolutePath, file_name: &str, data: Box<FixtureEnum>) -> FixtureEntry {
    let this_path = AbsolutePath::new(file_name, &parent_path);
    match *data {
        FixtureEnum::File(body) => {
            let body_iter = BufReader::new(StringReader::new(&body)).lines();
            let mut lines = Vec::new();
            for line in body_iter {
                lines.push(line.unwrap())
            }
            FixtureEntry {
                file_name: OsString::from(file_name),
                path: this_path,
                is_dir: false,
                content: FileFixtureContent { lines: RwLock::new(lines) },
            }
        },
        FixtureEnum::Dir(entries) => {
            let mut content = AHashMap::new();
            for (entry_name, entry) in entries.0 {
                let entry = convert_enum(&this_path, &entry_name, entry);
                content.insert(OsString::from(entry_name), Arc::new(entry));
            }
            trace!("Convert directory: {:?}", &content);
            FixtureEntry {
                file_name: OsString::from(file_name),
                path: this_path.clone(),
                is_dir: true,
                content: DirFixtureContent { entries: RwLock::new(content) },
            }
        },
    }
}

pub fn from_toml(toml_data: &str) -> Result<impl FileSystem> {
    let data : FixtureEnum = toml::from_str(toml_data)?;
    debug!("File system data: {:?}", data);
    Ok::<FixtureFileSystem, anyhow::Error>(data.into())
}

#[cfg(test)]
mod test {
    use std::pin::pin;
    use anyhow::bail;
    use indoc::indoc;
    use test_log::test;
    use tokio_stream::StreamExt;
    use crate::config_model::WriteMode::WriteNew;
    use crate::path::test_utils::to_absolute_path;
    use super::*;

    #[test]
    fn test_create_test_fixture_file_system() -> Result<()> {
        let fs = create_test_fixture_file_system()?;
        debug!("Improved test fixture file-system: {:?}", fs);
        Ok(())
    }

    #[test(tokio::test)]
    async fn read_dir() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;

        let entry_str = "other-dir";
        let parent_str = "top-dir";
        let path_os_string = OsString::from("/".to_string() + parent_str + "/" + entry_str);
        let parent = to_absolute_path(parent_str);

        // When
        let entries = read_dir_sorted(&fs, &parent).await?;

        // Then
        let expected = vec!["other-dir", "sibling-file", "sub-dir"].iter().map(OsString::from).collect::<Vec<_>>();
        let actual = entries.iter().map(DirEntry::file_name).collect::<Vec<_>>();
        assert_eq!(actual, expected);

        let entry = entries.get(0).unwrap();
        assert_eq!(entry.path(), path_os_string);
        assert!(entry.is_dir().await?);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_source() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let root = AbsolutePath::root();

        // When
        let mut source_file = fs.open_source(AbsolutePath::new("top-dir/sub-dir/file", &root)).await?;

        // Then
        let Some(first_line) = source_file.next_line().await? else { bail!("File is empty") };
        assert_eq!(&first_line, "First line");
        let Some(second_line) = source_file.next_line().await? else { bail!("File is too short") };
        assert_eq!(&second_line, "Second line");
        let Some(third_line) = source_file.next_line().await? else { bail!("File is too short") };
        assert_eq!(&third_line, "Third line");
        assert!(source_file.next_line().await?.is_none());

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_source_non_existent() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let dir = to_absolute_path("/not-found.txt");

        // When
        let result = fs.open_source(dir).await;

        // Then
        let Err(err) = result else { bail!("Opening a non-existent path should not be Ok") };
        assert!(err.to_string().starts_with("Not found:"), "Actual error: {:?}", &err);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_source_root() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let root = AbsolutePath::root();

        // When
        let result = fs.open_source(root).await;

        // Then
        let Err(err) = result else { bail!("Opening root as source should not be Ok") };
        assert!(err.to_string().starts_with("Trying to read lines from a directory:"), "Actual error: {:?}", &err);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_source_directory() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let dir = to_absolute_path("/top-dir");

        // When
        let result = fs.open_source(dir).await;

        // Then
        let Err(err) = result else { bail!("Opening a directory as source should not be Ok") };
        assert!(err.to_string().starts_with("Trying to read lines from a directory:"), "Actual error: {:?}", &err);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_source_file_in_file() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let dir = to_absolute_path("/.profile/file");

        // When
        let result = fs.open_source(dir).await;

        // Then
        let Err(err) = result else { bail!("Opening a file in a file should not be Ok") };
        assert!(err.to_string().starts_with("Not a directory:"), "Actual error: {:?}", &err);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_target_overwrite_existing() -> Result<()> {
        open_target_overwrite("top-dir/sub-dir/file").await
    }

    #[test(tokio::test)]
    async fn open_target_overwrite_new() -> Result<()> {
        open_target_overwrite("top-dir/sub-dir/new-file").await
    }

    #[test(tokio::test)]
    async fn open_target_overwrite_new_dir() -> Result<()> {
        open_target_overwrite("top-dir/new-dir/new-file").await
    }

    async fn open_target_overwrite(file: &str) -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let file_path = to_absolute_path(file);

        // When
        let Some(mut target_file) = fs.open_target(file_path.clone(), Overwrite, false).await? else { bail!("Could not open target") };
        target_file.write_line("Replacement").await?;
        target_file.close().await?;

        // Then
        let mut source_file = fs.open_source(file_path).await?;
        let Some(line) = source_file.next_line().await? else { bail!("New file is empty") };
        assert_eq!(&line, "Replacement");

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_target_dir_overwrite() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;

        let parent_str = "top-dir/other-dir";
        let parent = to_absolute_path(parent_str);

        // When
        let result = fs.open_target(parent, Overwrite, false).await;

        // Then
        let Err(err) = result else { bail!("Opening directory as target file should not be Ok") };
        assert!(err.to_string().starts_with("Trying to write lines to a directory"), "Actual error: {:?}", &err);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_target_dir_write_new() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;

        let parent_str = "top-dir/other-dir";
        let parent = to_absolute_path(parent_str);

        // When
        let target_file_option = fs.open_target(parent, WriteNew, false).await?;

        // Then
        assert!(target_file_option.is_none());
        Ok(())
    }

    #[test(tokio::test)]
    async fn open_target_root_ignore() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let root = AbsolutePath::root();

        // When
        let target_option = fs.open_target(root, Ignore, false).await?;

        // Then
        assert!(target_option.is_none());

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_missing_target_file_name() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let root = AbsolutePath::root();
        debug!("File name of root: {:?}", root.file_name());
        assert!(root.file_name().is_none());

        // When
        let result = fs.open_target(root, WriteNew, false).await;

        // Then
        let Err(err) = result else { bail!("Opening the root of the file-system should not be Ok") };
        assert!(err.to_string().starts_with("Missing file name:"), "Actual error: {:?}", &err);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_target_file_in_file() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let file_in_file = to_absolute_path("/.profile/file");

        // When
        let result = fs.open_target(file_in_file, WriteNew, false).await;

        // Then
        let Err(err) = result else { bail!("Opening a target file in a file should not be Ok") };
        assert!(err.to_string().starts_with("Not a directory:"), "Actual error: {:?}", &err);

        Ok(())
    }

    #[test(tokio::test)]
    async fn open_target_after_attempt_to_read_child_entry() -> Result<()> {
        // Given
        let fs = create_test_fixture_file_system()?;
        let new_file = to_absolute_path("/new");
        let file_in_file = to_absolute_path("/new/file");
        let result = fs.open_source(file_in_file).await;
        let Err(_) = result else { bail!("Opening a source file in a file should not be Ok") };

        // When
        let result = fs.open_target(new_file.clone(), WriteNew, false).await;

        // Then
        if let Some(mut target_file) = result? {
            target_file.close().await?;
        } else {
            bail!("It should be possible to writ to new file: {:?}", new_file);
        }

        Ok(())
    }

    // Implementation details

    #[test(tokio::test)]
    async fn write_to_dir() -> Result<()> {
        // Given
        let fixture_entry = FixtureEntry {
            file_name: OsString::from("foo"),
            path: to_absolute_path("/foo"),
            is_dir: true,
            content: DirFixtureContent {
                entries: RwLock::new(AHashMap::new())
            },
        };
        let entry = Arc::new(fixture_entry);

        // When
        let result = entry.write_line("Something").await;

        // Then
        let Err(err) = result else { bail!("Opening directory as target file should not be Ok") };
        assert!(err.to_string().starts_with("Trying to write a line to a directory"), "Actual error: {:?}", &err);

        Ok(())
    }

    // Utilities

    fn create_test_fixture_file_system() -> Result<impl FileSystem> {
        let toml_data = indoc! {r#"
            ".profile" = 'echo "Shell!"'

            [top-dir]
            sibling-file = "Foo"

            [top-dir.sub-dir]
            file = """
            First line
            Second line
            Third line
            """
            empty-file = ""

            [top-dir.sub-dir.empty-dir]

            [top-dir.other-dir]
            file = """
            Something completely different:
            The Larch
            """
        "#};
        trace!("TOML: [{}]", &toml_data);

        Ok(from_toml(toml_data)?)
    }

    async fn read_dir_sorted<FS: FileSystem>(fs: &FS, dir: &AbsolutePath) -> Result<Vec<FS::DirEntryItem>> {
        let mut dir_stream = pin!(fs.read_dir(&dir).await?);
        let mut entries = Vec::new();
        while let Some(entry_result) = dir_stream.next().await {
            entries.push(entry_result?)
        }
        entries.sort_by_key(|entry| entry.file_name());
        Ok(entries)
    }
}

impl Serialize for FixtureDirectory {
    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
    where
        S: Serializer
    {
        let mut map = serializer.serialize_map(Some(self.0.len()))?;
        for (k, v) in &self.0 {
            map.serialize_entry(k, v)?;
        }
        map.end()
    }
}