@@ -64,6 +64,32 @@ impl ScriptBuf {
64
64
/// Returns a mutable reference to unsized script.
65
65
pub fn as_mut_script ( & mut self ) -> & mut Script { Script :: from_bytes_mut ( & mut self . 0 ) }
66
66
67
+ /// Converts byte vector into script.
68
+ ///
69
+ /// This method doesn't (re)allocate.
70
+ pub fn from_bytes ( bytes : Vec < u8 > ) -> Self { ScriptBuf ( bytes) }
71
+
72
+ /// Converts the script into a byte vector.
73
+ ///
74
+ /// This method doesn't (re)allocate.
75
+ pub fn into_bytes ( self ) -> Vec < u8 > { self . 0 }
76
+
77
+ /// Converts this `ScriptBuf` into a [boxed](Box) [`Script`].
78
+ ///
79
+ /// This method reallocates if the capacity is greater than length of the script but should not
80
+ /// when they are equal. If you know beforehand that you need to create a script of exact size
81
+ /// use [`reserve_exact`](Self::reserve_exact) before adding data to the script so that the
82
+ /// reallocation can be avoided.
83
+ #[ must_use = "`self` will be dropped if the result is not used" ]
84
+ #[ inline]
85
+ pub fn into_boxed_script ( self ) -> Box < Script > {
86
+ // Copied from PathBuf::into_boxed_path
87
+ let rw = Box :: into_raw ( self . 0 . into_boxed_slice ( ) ) as * mut Script ;
88
+ unsafe { Box :: from_raw ( rw) }
89
+ }
90
+ }
91
+
92
+ impl ScriptBuf {
67
93
/// Creates a new script builder
68
94
pub fn builder ( ) -> Builder { Builder :: new ( ) }
69
95
@@ -78,16 +104,6 @@ impl ScriptBuf {
78
104
Ok ( ScriptBuf :: from_bytes ( v) )
79
105
}
80
106
81
- /// Converts byte vector into script.
82
- ///
83
- /// This method doesn't (re)allocate.
84
- pub fn from_bytes ( bytes : Vec < u8 > ) -> Self { ScriptBuf ( bytes) }
85
-
86
- /// Converts the script into a byte vector.
87
- ///
88
- /// This method doesn't (re)allocate.
89
- pub fn into_bytes ( self ) -> Vec < u8 > { self . 0 }
90
-
91
107
/// Adds a single opcode to the script.
92
108
pub fn push_opcode ( & mut self , data : Opcode ) { self . 0 . push ( data. to_u8 ( ) ) ; }
93
109
@@ -188,20 +204,6 @@ impl ScriptBuf {
188
204
None => self . push_opcode ( OP_VERIFY ) ,
189
205
}
190
206
}
191
-
192
- /// Converts this `ScriptBuf` into a [boxed](Box) [`Script`].
193
- ///
194
- /// This method reallocates if the capacity is greater than length of the script but should not
195
- /// when they are equal. If you know beforehand that you need to create a script of exact size
196
- /// use [`reserve_exact`](Self::reserve_exact) before adding data to the script so that the
197
- /// reallocation can be avoided.
198
- #[ must_use = "`self` will be dropped if the result is not used" ]
199
- #[ inline]
200
- pub fn into_boxed_script ( self ) -> Box < Script > {
201
- // Copied from PathBuf::into_boxed_path
202
- let rw = Box :: into_raw ( self . 0 . into_boxed_slice ( ) ) as * mut Script ;
203
- unsafe { Box :: from_raw ( rw) }
204
- }
205
207
}
206
208
207
209
impl < ' a > core:: iter:: FromIterator < Instruction < ' a > > for ScriptBuf {
0 commit comments