flowey/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![expect(missing_docs)]
5#![forbid(unsafe_code)]
6
7//! The user-facing flowey API.
8//!
9//! Relying on `flowey_core` directly is not advised, as many APIs exposed at
10//! that level are only supposed to be used by flowey _infrastructure_ (e.g: in
11//! `flowey_cli`).
12
13/// Types and traits for implementing flowey nodes.
14pub mod node {
15    pub mod prelude {
16        // include all user-facing types in the prelude
17        pub use flowey_core::match_arch;
18        pub use flowey_core::node::user_facing::*;
19
20        // ...in addition, export various types/traits that node impls are
21        // almost certainly going to require
22        pub use anyhow;
23        pub use anyhow::Context;
24        pub use fs_err;
25        pub use log;
26        pub use serde::Deserialize;
27        pub use serde::Serialize;
28        pub use std::path::Path;
29        pub use std::path::PathBuf;
30
31        /// Extension trait to streamline working with [`Path`] in flowey.
32        pub trait FloweyPathExt {
33            /// Alias for [`std::path::absolute`]
34            fn absolute(&self) -> std::io::Result<PathBuf>;
35
36            /// Helper to make files executable on unix-like platforms
37            fn make_executable(&self) -> std::io::Result<()>;
38        }
39
40        impl<T> FloweyPathExt for T
41        where
42            T: AsRef<Path>,
43        {
44            fn absolute(&self) -> std::io::Result<PathBuf> {
45                std::path::absolute(self)
46            }
47
48            fn make_executable(&self) -> std::io::Result<()> {
49                #[cfg(unix)]
50                {
51                    use std::os::unix::fs::PermissionsExt;
52                    let path = self.as_ref();
53                    let old_mode = path.metadata()?.permissions().mode();
54                    fs_err::set_permissions(
55                        path,
56                        std::fs::Permissions::from_mode(old_mode | 0o111),
57                    )?;
58                }
59                Ok(())
60            }
61        }
62    }
63}
64
65/// Types and traits for implementing flowey pipelines.
66pub mod pipeline {
67    pub mod prelude {
68        pub use flowey_core::pipeline::user_facing::*;
69    }
70}
71
72/// Types and traits for implementing flowey patch functions.
73pub mod patch {
74    pub use flowey_core::patch::*;
75    pub use flowey_core::register_patch;
76}
77
78/// Utility functions.
79pub mod util {
80    pub use flowey_core::util::*;
81}