vfs/
pseudo_directory.rs

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
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! A macro to generate pseudo directory trees using a small DSL.

use zx_status::Status;

/// A helper function used by the `pseudo_directory!` macro, to report nice errors in case
/// add_entry() fails.
#[doc(hidden)]
pub fn unwrap_add_entry_span(entry: &str, location: &str, res: Result<(), Status>) {
    if res.is_ok() {
        return;
    }

    let status = res.unwrap_err();
    let text;
    let error_text = match status {
        Status::ALREADY_EXISTS => "Duplicate entry name.",
        _ => {
            text = format!("`add_entry` failed with an unexpected status: {}", status);
            &text
        }
    };

    panic!(
        "Pseudo directory tree generated via pseudo_directory! macro\n\
         {}\n\
         {}\n\
         Entry: '{}'",
        location, error_text, entry
    );
}