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::node::user_facing::*;
18
19 // ...in addition, export various types/traits that node impls are
20 // almost certainly going to require
21 pub use anyhow;
22 pub use anyhow::Context;
23 pub use fs_err;
24 pub use log;
25 pub use serde::Deserialize;
26 pub use serde::Serialize;
27 pub use std::path::Path;
28 pub use std::path::PathBuf;
29
30 /// Extension trait to streamline working with [`Path`] in flowey.
31 pub trait FloweyPathExt {
32 /// Alias for [`std::path::absolute`]
33 fn absolute(&self) -> std::io::Result<PathBuf>;
34
35 /// Helper to make files executable on unix-like platforms
36 fn make_executable(&self) -> std::io::Result<()>;
37 }
38
39 impl<T> FloweyPathExt for T
40 where
41 T: AsRef<Path>,
42 {
43 fn absolute(&self) -> std::io::Result<PathBuf> {
44 std::path::absolute(self)
45 }
46
47 fn make_executable(&self) -> std::io::Result<()> {
48 #[cfg(unix)]
49 {
50 use std::os::unix::fs::PermissionsExt;
51 let path = self.as_ref();
52 let old_mode = path.metadata()?.permissions().mode();
53 fs_err::set_permissions(
54 path,
55 std::fs::Permissions::from_mode(old_mode | 0o111),
56 )?;
57 }
58 Ok(())
59 }
60 }
61 }
62}
63
64/// Types and traits for implementing flowey pipelines.
65pub mod pipeline {
66 pub mod prelude {
67 pub use flowey_core::pipeline::user_facing::*;
68 }
69}
70
71/// Types and traits for implementing flowey patch functions.
72pub mod patch {
73 pub use flowey_core::patch::*;
74 pub use flowey_core::register_patch;
75}
76
77/// Utility functions.
78pub mod util {
79 pub use flowey_core::util::*;
80}