yash_semantics/runtime.rs
1// This file is part of yash, an extended POSIX shell.
2// Copyright (C) 2025 WATANABE Yuki
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17//! Definition of `Runtime`
18
19use std::fmt::Debug;
20use yash_env::job::{RunBlocking, RunUnblocking};
21use yash_env::subshell::BlockSignals;
22use yash_env::system::concurrency::{ReadAll, Select, WaitForSignals, WriteAll};
23use yash_env::system::resource::SetRlimit;
24use yash_env::system::{
25 Clock, Close, Dup, Exec, Exit, Fcntl, Fork, Fstat, GetPid, GetPw, IsExecutableFile, Isatty,
26 Open, Pipe, Read, Seek, SendSignal, SetPgid, ShellPath, TcSetPgrp, Wait,
27};
28use yash_env::trap::SignalSystem;
29
30/// Runtime environment for executing shell commands
31///
32/// This trait combines various capabilities required for command execution and
33/// word expansion into a single trait. Since the implementation of command
34/// execution and word expansion is mutually recursive, any trait needed for any
35/// part of the implementation is transitively required by most of the
36/// implementation. Therefore, this trait serves as a convenient shorthand to
37/// express the required capabilities.
38pub trait Runtime:
39 BlockSignals
40 + Clock
41 + Close
42 + Debug
43 + Dup
44 + Exec
45 + Exit
46 + Fcntl
47 + Fork
48 + Fstat
49 + GetPid
50 + GetPw
51 + IsExecutableFile
52 + Isatty
53 + Open
54 + Pipe
55 + Read
56 + ReadAll
57 + RunBlocking
58 + RunUnblocking
59 + Seek
60 + Select
61 + SendSignal
62 + SetPgid
63 + SetRlimit
64 + ShellPath
65 + SignalSystem
66 + TcSetPgrp
67 + Wait
68 + WaitForSignals
69 + WriteAll
70{
71}
72
73/// Any type automatically implements `Runtime` if it implements all the
74/// supertraits of `Runtime`.
75impl<S> Runtime for S where
76 S: BlockSignals
77 + Clock
78 + Close
79 + Debug
80 + Dup
81 + Exec
82 + Exit
83 + Fcntl
84 + Fork
85 + Fstat
86 + GetPid
87 + GetPw
88 + IsExecutableFile
89 + Isatty
90 + Open
91 + Pipe
92 + Read
93 + ReadAll
94 + RunBlocking
95 + RunUnblocking
96 + Seek
97 + Select
98 + SendSignal
99 + SetPgid
100 + SetRlimit
101 + ShellPath
102 + SignalSystem
103 + TcSetPgrp
104 + Wait
105 + WaitForSignals
106 + WriteAll
107{
108}