Skip to main content

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    + Clone
42    + Close
43    + Debug
44    + Dup
45    + Exec
46    + Exit
47    + Fcntl
48    + Fork
49    + Fstat
50    + GetPid
51    + GetPw
52    + IsExecutableFile
53    + Isatty
54    + Open
55    + Pipe
56    + Read
57    + ReadAll
58    + RunBlocking
59    + RunUnblocking
60    + Seek
61    + Select
62    + SendSignal
63    + SetPgid
64    + SetRlimit
65    + ShellPath
66    + SignalSystem
67    + TcSetPgrp
68    + Wait
69    + WaitForSignals
70    + WriteAll
71{
72}
73
74/// Any type automatically implements `Runtime` if it implements all the
75/// supertraits of `Runtime`.
76impl<S> Runtime for S where
77    S: BlockSignals
78        + Clock
79        + Clone
80        + Close
81        + Debug
82        + Dup
83        + Exec
84        + Exit
85        + Fcntl
86        + Fork
87        + Fstat
88        + GetPid
89        + GetPw
90        + IsExecutableFile
91        + Isatty
92        + Open
93        + Pipe
94        + Read
95        + ReadAll
96        + RunBlocking
97        + RunUnblocking
98        + Seek
99        + Select
100        + SendSignal
101        + SetPgid
102        + SetRlimit
103        + ShellPath
104        + SignalSystem
105        + TcSetPgrp
106        + Wait
107        + WaitForSignals
108        + WriteAll
109{
110}